Solved

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

Posted on 2012-12-28
4
355 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Fine Tune your automatic Updates for Ubuntu / Debian
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now