Shel Script question

I am on RHEL 5.6, service IDs are created using bash by default

I have some software that starts with the following on a installed user ID

#!/bin/sh
##-----------------------------------------------------------------------------
##

Open in new window


How do I tell if this is ksh, bash, etc ?
Los Angeles1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AmickCommented:
Bourne Shell is sh
woolmilkporcCommented:
sh often is a hard link to another shell.

Put the statements

echo "shell?" $SHELL

and

echo "bash?" $BASH

into the script and see what you get.

If the first line shows something containing "bash" and the second line shows "bash? /bin/sh" it's bash.

If the fist line shows "shell? /bin/sh" and the second line shows only "bash?" it's indeed Bourne Shell.

If the fist line shows "shell? /bin/ksh" and the second line shows only "bash?" it's Korn Shell.

You can also run from commandline

/bin/sh --version

What do you see? If you get just a prompt it should again be Bourne Shell, if you see bash version info its ... bash.
If you see an error message "Invalid Flag" it should be ksh.

wmp






Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
arnoldCommented:
First line usually means run this script using the following shell. (#!)
items starting with # are comments..
For centos 5.6 /bin/sh is bash.
What is your question?
Is there an issue?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

TintinCommented:
If you do

ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Feb 14  2011 /bin/sh -> bash

Open in new window


you'll see /bin/sh is linked to bash.
AmickCommented:
Although the other experts have offered good ideas to understand what is really being fired up when the Bourne Shell is requested, your question is related to a script that starts #!/bin/sh. By convention the hash bang syntax (#!) indicates the facilities required to execute the script and using #!/bin/sh means the commands within the script will require only the facilities available in the Bourne Shell no matter what shell eventually provides those services.  Scripts that require other facilities start with other #! statements. For example, #!/usr/bin/perl requires Perl to execute, and #!/bin/ksh requires the Korn Shell.  The fact that RHEL uses bash by default doesn't present an impediment in any of these cases.
TintinCommented:
Amick.

That's not correct.   It's true that invoking /bin/sh on RHEL won't give you exactly the same behaviour as using /bin/bash, but it is very similar.

The only real difference is the following as described from the bash man page

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming  to  the  POSIX  standard as well.  When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands  from /etc/profile and ~/.profile, in that order.  The --noprofile option may be used to inhibit this behavior.  When invoked as an  interactive  shell  with  the   name  sh,  bash  looks  for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute.  Since a  shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option  has  no  effect.   A  non-interactive  shell  invoked with the name sh does not attempt to read any other startup files.  When invoked as sh, bash enters posix mode after the startup files are read.
AmickCommented:
Tintin,

I'm sorry, but I don't see the error you're attempting to correct. Are you contending that RHEL's use of bash does indeed present an impediment to executing a script which requests #!/bin/sh due to its slightly imperfect emulation of sh?
TintinCommented:
Perhaps I'm misunderstood what you meant.

When you said:


By convention the hash bang syntax (#!) indicates the facilities required to execute the script and using #!/bin/sh means the commands within the script will require only the facilities available in the Bourne Shell no matter what shell eventually provides those services

I interpreted that as you saying that if you use #!/bin/sh on a system where /bin/sh is linked to another shell, it will function as a bourne shell.

This is not the case, as you can use bash constructs (on RHEL and similar distros where /bin/sh is linked to bash) even if your script starts with #!/bin/sh

Apologies if I have not understood your point.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.