Solved

how to set the shell to bash if there is bash otherwise set to ksh

Posted on 2012-12-28
5
575 Views
Last Modified: 2013-01-09
I am in linux , aix , solaris

Usually there is bash on the box, sometimes not
if there is bash on the box, I want to run my scripts in bash.
if there is not bash on the box THERE WILL BE KSH and i would like to set my scripts to run
in ksh ( so it does not default to sh )

how can I do this ?
0
Comment
Question by:TIMFOX123
[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 22

Expert Comment

by:mcsween
ID: 38727564
You can set your default shell per user in /etc/passwd.  Just change the last option on the line from /bin/sh to /bin/bash or /bin/ksh

This link explains the /etc/passwd layout
http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38727672
Omit the shebang line #!...

and call your script like

[[ -x /bin/bash ]] && INTP=/bin/bash || INTP=/bin/ksh; $INTP /path/to/script

If your default login shell is either bash or ksh then you can do

$SHELL /path/to/script

Here too you must omit #!...
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38727938
This is another trick.

Prefix your script (again without the shebang) with the following code (I took the first part from your other question):

function shellselect {
if [[ -e "/bin/bash" ]];  then
                INTERP="/bin/bash"
                else
                                INTERP="/bin/ksh"
fi; }

if [[ $1 != "12345selected54321" ]];  then
   shellselect
   $INTERP $0 "12345selected54321" "$@"
   exit
   else shift
fi
# actual code starts here, next two lines just for demonstration ...
echo $BASH # line will be empty if ksh is used, else it will contain the path to bash.
echo $@ # to show that the params are still there
# ....
# ....
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 38728085
Do the servers that have bash also have ksh?

If so, then just add

#!/bin/ksh

to your scripts
0
 

Author Closing Comment

by:TIMFOX123
ID: 38761025
Thank you so much everybody but Tintin just hit this one 100%

thx Tintin
0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

622 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