korn shell - not able to see

ittechlab
ittechlab used Ask the Experts™
on
[root@myserver~]# /bin/ksh
# echo $SHELL
/bin/bash

I wonder why ksh is not showing up when i did ksh or /bin/ksh?

I am used with bash, specific app uses ksh so i had to switch.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
nociSoftware Engineer
Distinguished Expert 2018

Commented:
may be someone made a symlink to be able to run ksh scripts?
Please show the output of the next commands for verification:

ls -li /bin/ksh
ls -li /bin/bash

Open in new window

ittechlabLinux Support

Author

Commented:
[root@server~]# ls -li /bin/ksh
204546 lrwxrwxrwx 1 root root 21 jan 20 2014 /bin/ksh -> /etc/alternatives/ksh
ittechlabLinux Support

Author

Commented:
[root@server~]# ls -li /bin/bash
204734 -rwxr-xr-x 1 root root 736348 Sep 25  2014 /bin/bash
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

nociSoftware Engineer
Distinguished Expert 2018

Commented:
right ksh point to /etc/alternatives/ksh so no to check that...

ls -li  /etc/alternatives/ksh

Open in new window


If this again shows a symlink the use ls -li on that as well
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Rarely, if ever, is a real ksh available... unless you manually install it, via your package manger or from source.

Mention OS you're running.

Also, how you ended up with /bin/ksh pointing to /bin/bash, if you know... as, this symlink likely should be released, as there are major differences.

Specifically, you can't expect bash to correctly execute ksh code.

While, ksh will usually correctly execute bash code.
Duncan RoeSoftware Developer

Commented:
To save repeated ls commands, try readlink -f /bin/ksh. But I think you'll find it's a real ksh.
ksh is standard on my system (Slackware) and in my FC28 (Red Hat) VM I fetched ksh by yum install. In both cases, I found that I could invoke ksh but $SHELL remained unchanged.
The man page for ksh says
The shell gives default values to PATH, PS1, PS2, PS3,  PS4,  MAILCHECK, FCEDIT,  TMOUT  and IFS, while HOME, SHELL, ENV, and MAIL are not set at all by the shell (although HOME is set by login(1)). On some systems MAIL and SHELL are also set by login(1).
Here's how you can be sure you are not running bash: enter shopt. This is a bash built-in command (short for shell options). Under ksh you will get
ksh: shopt: not found [No such file or directory]
ittechlabLinux Support

Author

Commented:
there is ksh is  available on this server as there is another userd id able to use ksh. not sure why I am not able to use as root account or my account?
Duncan RoeSoftware Developer

Commented:
root is able to use ksh. You are using it. ksh does not change SHELL - that is not the way to test what shell you are running. SHELL only says what is your default shell (from /etc/profile).
Try issuing shopt after you have issued /bin/ksh. If that fails, you are not running bash any more.
Also try issuing ps. Expect to see something like
  PID TTY          TIME CMD
12533 pts/14   00:00:00 bash
13271 pts/14   00:00:00 ksh
13272 pts/14   00:00:00 ps

Open in new window

Hi David.

Here are some comments on some of your comments:

> "Also, how you ended up with /bin/ksh pointing to /bin/bash, if you know... as, this symlink likely should be released, as there are major differences."
Please quote the text which lead you to believe ittechlab's /bin/ksh is pointing to /bin/bash.

> "Specifically, you can't expect bash to correctly execute ksh code.
> While, ksh will usually correctly execute bash code."

I thought the reverse was true, and just did a quick search and found this which seems to support my understanding:
    http://www.differencebetween.net/technology/difference-between-ksh-and-bash/
While I doubt all ksh scripts will run under bash, some relevant quotes from that page are:
 "A syntax in the KSH shell can run in a Bash shell without encountering errors or problems."
 "Bash also acts as an extension of the Korn shell, since it incorporates the features of the latter, with some added features."
Can you link to anything which supports your opposing understanding?
nociSoftware Engineer
Distinguished Expert 2018

Commented:
The family tree is bsh -> ksh (improvement on bsh).   and in then  bsh -> bash (also improvement on bsh)
bash is based on free sources whereas ksh was built initialy on restrictive copyrighted (until 2005) sources.
That why bash gained traction in Linux and ksh more in unix environments.

bash (Bourne Again Shell)  and ksh (Korn Shell) both stem from bsh (Bourne Shell).
bash also took some ideas from ksh expanded on them.
As such lots of ksh script run under bash but not the other way around.

That's also why the alternatives package can use a symlink from ksh -> bash to run scripts.. (most of the times).
Duncan RoeSoftware Developer

Commented:
@noci I never heard of the Bourne shell being called bsh - only sh ?
Duncan RoeSoftware Developer

Commented:
Also bash got some ideas from csh (C shell) - at least history editing IIRC
nociSoftware Engineer
Distinguished Expert 2018

Commented:
History recall was also in ksh, but it needed some special setup due to keyboard issues.  (keystroke editting, not the ! edditing).

bsh is the name used by the package managers.  
and yes it used to be /bin/sh..., but that being a generic name meant that most shells setup a symlink to themselves  names /bin/sh.
Duncan RoeSoftware Developer

Commented:
Back to the original question: the SHELL environment variable is not there to say which shell is running currently: it's there to tell programs that issue shell commands which shell they should use to do so. No surprise when SHELL does not change on invoking ksh therefore.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial