Which shell is the best in startup scripts?

Posted on 2005-04-05
Medium Priority
Last Modified: 2010-04-20
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:

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

Can I change the first line to

Thank you.
Question by:beaverton8770
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Expert Comment

ID: 13709232
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

Assisted Solution

pdub79 earned 500 total points
ID: 13709657
#!/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...

Accepted Solution

fixnix earned 1000 total points
ID: 13710118
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.
LVL 38

Assisted Solution

wesly_chen earned 500 total points
ID: 13710243
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.



Author Comment

ID: 13710514
Thank you Experts.

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

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question