?
Solved

Which shell is the best in startup scripts?

Posted on 2005-04-05
5
Medium Priority
?
384 Views
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:

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

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

Thank you.
0
Comment
Question by:beaverton8770
[X]
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
5 Comments
 
LVL 16

Expert Comment

by:manav_mathur
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
0
 
LVL 3

Assisted Solution

by:pdub79
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...
http://www.faqs.org/docs/linux_intro/x7132.html
0
 
LVL 9

Accepted Solution

by:
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.
0
 
LVL 38

Assisted Solution

by:wesly_chen
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.

Regards,

Wesly
0
 

Author Comment

by:beaverton8770
ID: 13710514
Thank you Experts.

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

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