Question

I've recently switched to the ksh93 shell. I did this by adding the following two lines to my .profile file

export SHELL=/usr/local/bin/ksh93
exec $SHELL

Since I did that some simple scripts have started misbehaving in a way I don't understand. I narrowed it down to the following simple script called say test.sh

#!/bin/ksh
echo $0 $1

If I type the command test.sh fred I would expect to see the same output test.sh fred. Instead I see test.sh noglob. If I remove the shebang or if I change it to read #!/usr/local/bin/ksh93 then the script works as expected.

Can anyone explain what's going on, or what to do about it? I'm stumped.

I'm using Solaris 5.9 if it makes any difference.

Was it helpful?

Solution

I notice from the comments that your .kshrc has a set noglob. The set command with no options will set the command-line parameters, which is why $1 is "noglob", it should be set -o noglob.

By the way, setting noglob is weird, are you sure you want that?

I suspect (as others have mentioned) that /bin/ksh is Korn shell 88.
There is an important difference between ksh88 and ksh93 with regards to .kshrc. On ksh88 .kshrc is executed for every korn shell process, even non-interactive ones (scripts). In ksh93 .kshrc is not executed for shell scripts, only for interactive login shells.

When you do exec $SHELL that is not a login shell, it is better to change your entry in /etc/passwd. By the way, using variable SHELL is a bad idea, since that is set by the login shell.

OTHER TIPS

There's probably an alias on ksh in your system with noglob set as an option, or noglob is being passed as a default parameter by default in your old shell. You should also check what ksh you're really calling (check if there's a link to another shell in from /bin/ksh). ksh --version should give some insight as well.

As a last point, instead of calling the shell directly i'd recommend to use

 #!/usr/bin/env ksh
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top