Solved

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

Posted on 2012-12-28
5
557 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 21

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
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…
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…
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.

821 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