Solved

is it valid to set the not in the first line of a script with #!

Posted on 2012-12-28
4
375 Views
Last Modified: 2013-01-09
I am a very important and  yet again mixed envirment.  

each machine has one of "bash or ksh"

If there is bash I want to use it, otherwise I can use ksh.   I never ever want to use "sh" because there are lines in my scripts  that will not run with an oversimplistic shell

Here is my solution and I need to know if people forsee a a problem with selecting your shell after the script starts.



 
## set environment so you never get /bin/sh !!!
if [[ -e "/bin/bash" ]];  then
                SHELL="/bin/bash"
                else
                                SHELL="/bin/ksh"
fi
 
echo $SHELL


Oh, I am in a redhat, solaris, aix envirement with either bash OR  ksh
0
Comment
Question by:TIMFOX123
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 38727758
The SHELL variable doesn't have any influence on which interpreter is used for the script.
It's a variable like any other one, and the shell itself never evaluates it.

Best use the code you posted as a wrapper to start your script:

if [[ -e "/bin/bash" ]];  then
                /bin/bash "$@"
                else
                                /bin/ksh "$@"
fi


Call this script e.g. "launch"

and run

launch /path/to/script param1 param2 param3 paramn

Please don't use a shebang line "#!/bin/bash" or "#!/bin/ksh" in the called scripts with the above solution.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38727971
Please see your other question on this topic for an "inline" solution!
0
 
LVL 48

Expert Comment

by:Tintin
ID: 38728097
What user will be invoking the script?

If their login shell is either bash or ksh depending on the environment, then simply omit the #! line on the script/s and it will run under the shell of the user that is running the script.
0
 

Author Closing Comment

by:TIMFOX123
ID: 38761021
Sorry for me taking so long to get back.  I work all the time and rarely get out to the "real internet "

thanks porky
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

809 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