What is the difference between bash scripting and ksh scripting

I have been writing bash for 10 years,

Now they want ksh

Time to learn :)

TIMFOX123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steven CarnahanNetwork ManagerCommented:
BASH = Bourne Again SHell

ksh = Korn SHell

There are many other variaties of shell programming as well. This site has a good discussion of the differences:    http://www.unix.com/answers-frequently-asked-questions/12274-difference-between-ksh-bash-different-shells.html
TIMFOX123Author Commented:
What do I have to change to convert my bash scripts to ksh ?

I tried to run a subroutine script written for bash in ksh and the results were not pretty.
TintinCommented:
>99% of scripts written in bash will work under ksh without modification.

Are you able to post your bash function that doesn't work under ksh?
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Steven CarnahanNetwork ManagerCommented:
Maybe this will help better.  It contains a list that ksh has that bash doesn't and the other way around: http://sawaal.ibibo.com/computers-and-technology/how-bash-differ-from-korn-shell-version-ksh88-571379.html

 It is difficult to explain what you need to do to conver without a sample of what didn't work.
TIMFOX123Author Commented:
output=output.txt

#########
#       The purpose of this function it to recive a shell command string (SS)
#       Echo a begin marker with hostname and (SS)
#       Echo the results of (SS)
#       Echo a end marker just like the start marker
#       except the begin marker has "b" and the end has "e"
#
#########



# clear out old output.txt
echo > ${output}

function doo(){

echo "tqf####~"$hostname"~${1}~b~####" >> ${output}
echo  >> ${output}

${1}  >> ${output}

:q!
bash-3.00$ cat yada
output=output.txt

#########
#       The purpose of this function it to recive a shell command string (SS)
#       Echo a begin marker with hostname and (SS)
#       Echo the results of (SS)
#       Echo a end marker just like the start marker
#       except the begin marker has "b" and the end has "e"
#
#########



# clear out old output.txt
echo > ${output}

function doo(){

echo "tqf####~"$hostname"~${1}~b~####" >> ${output}
echo  >> ${output}

${1}  >> ${output}

echo  >> ${output}
echo "tqf####~"$hostname"~${1}~e~####" >> ${output}
echo  >> ${output}

}

## note all commands commented out were try and did not work on REDHAT 5.5.
## most of the commented out commands are likely for redhat or software I do not               have on my solaris system
## I do not have access to a solaris server with zones and want to have solaris               admin write that part of the code
## to get ip addresses for virtual zones from the host solaris 10 OS






doo "/bin/df"
doo "/bin/netstat"
doo "/bin/ps"
doo "/bin/uname"
doo "/usr/bin/ipcs"
doo "/usr/bin/uptime"
doo "cat /etc/hosts"
doo "cat /etc/nsswitch.conf"
doo "cat /etc/passwd"
doo "cat /etc/resolv.conf"
doo "cat /etc/services"
doo "crontab -l"
doo "df -k"
doo "domainname"
doo "hostname"
doo "ls -d"
doo "ls -l"
doo "mount"
doo "netstat -a"
doo "netstat -an"
doo "netstat -ng"
doo "pkginfo -i"
doo "pkginfo -l"
doo "ps -ef"
doo "uname -a"
doo "uname -r"
doo "uname"
doo "vmstat"
doo "showrev -p"
doo "swap -l"
doo "crontab -l"
doo "prtvtoc /dev/rdsk/"
doo "ifconfig -a"
doo "cat /etc/vfstab"
doo "cat /etc/aliases"
doo "cat /etc/sudoers"
doo "cat /etc/inittab"
#doo "prtdiag"
#doo "raidctl"
doo "iostat"
#doo "zpool status -v"
TIMFOX123Author Commented:
run fine in bash.  

In ksh:

bash-3.00$ ./y2
./y2[18]: syntax error at line 18 : `(' unexpected
TintinCommented:
You just to remove the parentheses, so that

function doo() {

becomes

function doo {


In bash the parentheses are optional if you use the 'function' reserved word.  They are only needed if you omit the 'function.

So the following are all equivalent in bash

function doo() {

function doo {

doo() {

The last form is also compatible with both ksh and bourne shell

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TintinCommented:
BTW, I'd write your function as:


#!/bin/ksh
exec 1>output.txt


function doo {
  echo "tqf####~"$hostname"~${1}~b~####"
  echo

  $*

  echo
  echo "tqf####~"$hostname"~${1}~e~####"
  echo
}

Open in new window

TIMFOX123Author Commented:
thank you so much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.