Which shell can I use on Linux?

I have Linux x86_64 x86_64 x86_64 GNU/Linux
I thought that Linux can use only bash shell
however, when I wrote the code:

 #!/bin/sh
 NAME=`basename $0 .sh`
Today=`date '+%Y%m%d'`
TIMESTAMP=`date +%H:%M:%S`
LOCAL_SERVER=`hostname`
 let countcla=0
 countcla=`expr ${countcla} + 1`
 echo "${NAME} ${Today} ${TIMESTAMP} ${LOCAL_SERVER} ${countcla}"
exit
 

the result was

 test 20170627 16:15:48 gbdted01.us.db.com 1
 

Does it means I can use any shell, not ONLY BASH? Does it mean that I don't have to convert my old shell scripts to bash?

Thanks for contribution

bash is many linux distributions' standard (or preinstalled) shell, but almost any comes with a sh (which, in turn, may be still another, e.g. dash , in disguise, or even a link to bash mimicing sh ). And, any shell can be installed by the user. Look into your distribution's package manager.

Where can I find distribution's package manager

That depends on the distribution you use (and which you failed to mention, btw); there are quite some. Ubuntu / Debian have synaptic, Fedora use yum, and RedHat have their RPM.

I am not admin. I am just trying to understand, if I need to convert sh /ksh to bash or not

---------- Post updated at 04:56 PM ---------- Previous update was at 04:52 PM ----------

BTW, I have RedHot

Then ask your admin to install the ksh - rpm.

1 Like

When I test bash command, the script doesn't give an error, it just doesn't print value

 MYSHELL=$(ps -hp $$|awk '{echo $5}')
 

print

 MYSHELL IS
 

I believe it is ksh

Of course it doesn't print anything as you didn't tell it to print anything. Do you know about the $SHELL variable?

Also echo is not a awk action statement you are probably after print :

$ ps -hp $$ | awk '{ echo $5 }'
$ ps -hp $$ | awk '{ print $5 }'
-bash

Is it really necessary to be admin, i.e. is there a disadvantage (for instance, some features not working) if one installs shells locally? At least with other programming languages (Perl, Ruby, Python, ...), if I'm on a centrally administered system where I don't have admin rights, I prefer to install them in my $HOME instead of requesting an admin to do this just for me, because I can then easier control the version I'm using etc.

Are there features in shells, which would cause trouble with this approach? I'm aware that if I'm not admin, I can't put any shell-specific startup file into /etc, but I would see it only as a minor issue.

the script below:

 #!/bin/ksh
  
 NAME=`basename $0 .sh`
Today=`date '+%Y%m%d'`
TIMESTAMP=`date +%H:%M:%S`
LOCAL_SERVER=`hostname`
 let countcla=0
 countcla=`expr ${countcla} + 1`
 echo "${NAME} ${Today} ${TIMESTAMP} ${LOCAL_SERVER} ${countcla}"
MYSHELL=$(ps -hp $$|awk '{print $5}')
echo "MYSHELL IS ${MYSHELL}"
MYSHELL=`ps -hp $$|awk '{print $5}'`
echo "MY NEW SHELL IS ${MYSHELL}"
exit

 

Doesn't matter what I put in the first line

#!/bin/ksh

or

#!/bin/bash

both are working. The different is only if

 #!/bin/bash
 

result is

 test 20170628 08:58:12 gbdted01.us.db.com 1
MYSHELL IS /bin/bash
MY NEW SHELL IS /bin/bash
 

if I make

 #!/bin/ksh
 

the result is

 test 20170628 08:58:56 gbdted01.us.db.com 1
MYSHELL IS /bin/ksh
MY NEW SHELL IS /bin/ksh
 

So, my question is: what do I have installed Korn shell or bash? Obviously, I don't have to change old shell scripts, they will work. However, what will be working better, faster and code easier, ksh or bash?
That is what I have to tell to my manager. If bash easy to code and work faster, then we can request to install bash rpm.

What would you propose?

Thanks for contribution

You have obviously both shells installed, and your code happens to be compatible to both (bash and ksh share a common language subset). Looking at your code, I guess it would also work with Zsh and Posix shell and even csh (but who wants to program in csh anyway). I don't know much about speed issues: Do you plan to write shell scripts which don't do much I/O, but mainly in-memory processing? If you are absolutely free to choose the shell, select the one which you like best. For instance, I consider Zsh most powerful and convenient from the programmer's point of view, but I know also programmers who say the same about bash or ksh.

Note also that you have to take account the version of the respective shell, because features change between versions. I would prefer working with a very recent bash over a very old Zsh....

As rovf says, you seem to have either installed.
Please be aware that your script will be executed in a subshell invoked with the interpreter named in the shebang (the very first line in the script if starting with EXACTLY #! - no space allowed as opposed to what you have in your example). So that doesn't say anything about your login shell. Try a simple echo $0 at the command prompt to see what that would be.

rovf, all our scripts are using I/O, we are reading files or getting data from database and cerate reports, some - small, some - huge.

RudiC

 echo $0

gives me

-ksh

If we have bash installed, I would go with bash, but it depends of big boss.
But what is you advise, which I can send to my manager use bash or use ksh? Of course the problem will get into "money" issue. If we have to change all scripts to bash, then I don't know if budget allows company to do it. Anyway, I need your advise what to tell my manager to persuade him to go with bash

Thanks for contribution

Looks like your login shell is ksh .
I have to admit that I don't really understand your problem. Why do you ask if you vave to "convert sh /ksh to bash" if ALL your scripts should be running flawlessly with ksh as login shell? Both ksh and bash will run sh scripts as is as they offer a superset of sh syntax.
Where exactly do you run into problems?

1 Like

If your scripts are all written in ksh already, you should insist all your systems are installed with ksh in addition to bash . It will cost your company next to nothing compared with testing and modifying each script.

Andrew

1 Like

Yes, if you want ksh, install ksh. It's significantly different from both BASH and SH, in ways that might not matter or might fundamentally alter how your scripts are written (pipe subshell ordering).

Note there is more than one kind of ksh. There's crusty old-fashioned ksh88, which your distro likely has as pdksh, and modern fuller featured ksh93.

I didn't work a lot in ksh - as I said, I'm a Zsh guy - and do not know where ksh shines over bash. I would be surprised if in your case one had a noticeable performance advantage over the other.

If the choice is between bash and ksh, and money is and issue, you might argue in favour of bash, because this is by default installed on virtually any system I know. If you transfer your application to a new host, it might be that you would have to install ksh first, and since people don't do it in their free time, it indeed costs a litte bit.

Also, if you get stuck somewhere and search for help on the Net, many more people know bash than ksh (or Zsh, for this matter), and can help you. Still, given that bash and ksh have a lot in common, this is a small advantage.

So, my recommendation: First try to find on the Net a page comparing the features of ksh and bash. If you don't find anything which, in your opinion, is a big advantage for ksh, you don't make a mistake when going for bash.

Hi.

I use mostly bash and some ksh . However, there are many more shells, several of which are special purpose, and many look interesting. For example, fish shell is cross-platform and seems to have a lot of features for interactive work. Here is a list with links:

Linux Links - The Linux Portal: Software/Shells

and here is a detailed comparison of the most-often encountered shells:

Comparison of command shells - Wikipedia

Best wishes ... cheers, drl