Solved

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

Posted on 2012-12-28
4
341 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
Comment Utility
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
Comment Utility
Please see your other question on this topic for an "inline" solution!
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
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
Comment Utility
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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

771 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

11 Experts available now in Live!

Get 1:1 Help Now