LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices


Reply
  Search this Thread
Old 07-10-2002, 05:51 AM   #1
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
Is it possible to replace sh?


I suffer from the behaviour of sh in my FreeBSD 4.6 distribution.
Constructs like:
let FAILED=$FAILED +1
do not work, I have to use
FAILED="$FAILED"+1
instead.

Because of this, almost no shell scripts written on my home Linux machine or downloaded from the internet work.
What is the reason for this behaviour of sh in FreeBSD, and what is the best remedy? Please be a bit specific, I am a newbie to unixes.
 
Old 07-10-2002, 06:00 AM   #2
pickledbeans
Member
 
Registered: Jun 2002
Location: Bailey, CO
Distribution: Slackware
Posts: 483

Rep: Reputation: 32
do you mean sh (Borne) or Korn do
echo $SHELL

You could install port of BASH if thats what your looking
If your actually using sh instead of Korn do

chsh -s /pathto/korn
log out and back in to get you new env.
 
Old 07-10-2002, 06:30 AM   #3
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
I mean the shell in /bin/sh on the FreeBSD machine has a different behaviour (syntax) from the behaviour of /bin/sh on my linux machine.
Some programs explicitly call /bin/sh; and these programs will not work, no matter what my default script is.

So far as I can judge, the best solution would be to replace the present /bin/sh with an other sh version, if any, whose behaviour is closer to that usual on Linux. Are there different sh versions? (the one I have presently came with the FreeBSD release)?
 
Old 07-10-2002, 06:31 AM   #4
elb
LQ Newbie
 
Registered: Apr 2002
Posts: 19

Rep: Reputation: 0
let FAILED=$FAILED+1 is not valid sytax for sh, although it is valid syntax for bash

sh in most Linux distros is actually bash. sh is the bourne shell, bash is the bourne again shell. FreeBSD's sh really is sh.

If you haven't already, install bash2 via the ports system. Then change your scripts from #!/bin/sh to #!/usr/local/bin/bash If you want to change your login shell to bash, use chsh and change the /bin/sh line to /usr/local/bin/bash

Do NOT replace /bin/sh with a symlink to /usr/local/bin/bash. Don't do it. But you could place a symlink from /bin/bash to /usr/local/bin/bash if you really wanted to.
 
Old 07-10-2002, 07:29 AM   #5
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
> let FAILED=$FAILED+1 is not valid syntax for sh, although it is valid syntax for bash

You may be right, but I have a program (anomy e-mail sanitizer), which has a shell with the following lines:

#!/bin/sh
.
.
let FAILED=$FAILED+1

The above works well on Linux, and fails on FreeBSD.
How could it work on Linux, if the "let..." syntax is invalid in sh? If it works on Linux, why does not work on FreeBSD?
 
Old 07-10-2002, 08:45 AM   #6
elb
LQ Newbie
 
Registered: Apr 2002
Posts: 19

Rep: Reputation: 0
Quote:
Originally posted by J_Szucs
>How could it work on Linux, if the "let..." syntax is invalid in sh? If it works on Linux, why does not work on FreeBSD?
Please re-read the following statement very carefully:

Quote:
Originally posted by elb
>sh in most Linux distros is actually bash. sh is the bourne shell, bash is the bourne again shell. FreeBSD's sh really is sh.
Try this on your Linux box if you still don't understand:

$ diff /bin/sh /bin/bash

Then try this on your FreeBSD box:

$ diff /bin/sh /usr/local/bin/bash

See?
 
Old 07-10-2002, 01:03 PM   #7
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
I will try to summarize, please correct me if I am wrong:

1. I have to check any shells coming from Linux if it explicitly calls /bin/sh, and replace each occurance with /path/to/bash.

2. I will have no trouble with shells that do not explicitly call /bin/sh, since the default root shell is bash now.

But, just to be on the safe side, are there any tricky ways of explicitly calling /bin/sh that I cannot find with grep?
 
Old 07-26-2002, 02:00 AM   #8
rverlander
Member
 
Registered: May 2002
Distribution: A few
Posts: 488

Rep: Reputation: 30
Re-compile bash
 
Old 07-26-2002, 05:57 AM   #9
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
In theory, shell scripts that link to /bin/sh on Linux should work fine with FreeBSD's sh, because they should only use the features of sh and not bash's extensions.

Alex
 
Old 07-26-2002, 11:15 AM   #10
algould
LQ Newbie
 
Registered: Jul 2002
Distribution: FreeBSD 4.6 Stable, Mac OS X
Posts: 24

Rep: Reputation: 15
I was advised once never to change root's shell to any shell that is not located in /bin/. In FreeBSD sh and csh are located in /bin/.

I think the reason for this has to do with emergency bootup situations where /usr/ is not mounted and shells in /usr/local/bin/ would not be available.

I am not positive about my accuracy on this issue. Can anyone in this forum confirm/deny this?

Thanks,

Andrew Gould
 
Old 07-26-2002, 06:56 PM   #11
elb
LQ Newbie
 
Registered: Apr 2002
Posts: 19

Rep: Reputation: 0
You were advised well. And yes, that is the primary reason why you should not do so. It is the same reason you shouldn't symlink /tmp to /var/tmp or some such.

However, you can put your shell of choice in /bin, assuming it is statically linked.
 
Old 08-14-2002, 03:43 PM   #12
Dan Angelescu
RoFreeSBIE
 
Registered: Oct 2001
Posts: 81

Rep: Reputation: 15
Install bash .Afther instalation it will be located in /usr/local/bin/bash and make a symlink to it
ln - s /usr/local/bin/bash /bin/bash.
That's all you need to make work the linux scripts.
if you want to change the shell chsh - s /bin/bash.
Good luck!
 
Old 08-14-2002, 10:50 PM   #13
algould
LQ Newbie
 
Registered: Jul 2002
Distribution: FreeBSD 4.6 Stable, Mac OS X
Posts: 24

Rep: Reputation: 15
There is no need for a symbolic link. /usr/local/bin/ is in $PATH by default. If /usr/local/bin is in the same partition as /, then bash would be available during emergency boot up situations.

It is generally advised, however, that /usr/ be put in its own partition. If /usr/ is in its own partition and could not be mounted for some reason, the root user would not have access to it. In this case, the symbolic link would be useless.

Andrew Gould
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need to replace RH 9 ? juanb Linux - General 5 01-30-2004 08:32 PM
Replace HD CloudBuilder Linux - Hardware 1 11-03-2003 01:26 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM
What are you using to replace MS Office Ben_Ty Linux - Software 15 07-15-2003 02:36 PM
install 7.0 and replace RH 6.0 pyramid Linux - Software 1 03-26-2001 06:18 AM

LinuxQuestions.org > Forums > Other *NIX Forums > *BSD

All times are GMT -5. The time now is 03:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration