Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-12-28
5
Medium Priority
?
588 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
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

886 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