• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

Which shell is the best in startup scripts?

Hello Experts.

I am using Linux version from 2.2.4 to 2.4.29.
This question is about scripts in /etc/rc.d.

I've noted that they have first line #!/bin/sh
Does this mean that they invoke C-Shell?

If so, can I use Bash syntax in them? Probably not..
If I want to use, Bash syntax anyway, will them work if I change
first line to #!/bin/bash. In other words, will be Bash invoked on my machine
at startup?

If by some reason there are some considerations against
using Bash in startup scripts, were to find
manual which highligts differences between Bash and C-shell?
In other words what is a strategy to write safe but effective scripts?
For example, if I have a script:

#!/bin/bash
X=`cat moo | sed -n ' /d/d' `
echo "\n$X"

Can I change the first line to
#!/bin/sh
?

Thank you.
0
beaverton8770
Asked:
beaverton8770
3 Solutions
 
manav_mathurCommented:
Does this mean that they invoke C-Shell?
- no they invoke the very basic shell, not sure what it is called.

If so, can I use Bash syntax in them? Probably not..
- no
If I want to use, Bash syntax anyway, will them work if I change
first line to #!/bin/bash. In other words, will be Bash invoked on my machine
at startup?
- yes, why not
0
 
pdub79Commented:
#!/bin/sh - invokes the bourne shell

BASH is an offshoot of bourne (sh) so many of the commands are the same. BASH actually stands for BOURNE AGAIN SHELL

Here is a link that shows some of the difference between shells...
http://www.faqs.org/docs/linux_intro/x7132.html
0
 
fixnixCommented:
mail5:/var/cache/polipo# ls -l /bin/sh
lrwxrwxrwx  1 root root 4 2005-03-30 06:58 /bin/sh -> bash


/bin/sh invokes /bin/bash on most linux systems...just check if /bin/sh is a symbolic link like it is on one of mine above.
0
 
wesly_chenCommented:
As fixnix pointed out, in most Linux,
/bin/sh --> /bin/bash
/bin/csh --> /bin/tcsh
So change
#!/bin/bash   to  #!/bin/sh   will work without changinig any syntax in that script for most of case (unless you have very old Linux).
Also, #!/bin/sh  is more platform independent since /bin/sh is on all the Unix/Linux OS.

Regards,

Wesly
0
 
beaverton8770Author Commented:
Thank you Experts.

ls -l /bin/sh    is really a SOLUTION.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now