-1

my scripts are developed using a shebang line as "#!/bin/ksh" and the default shell is $ echo $SHELL /bin/ksh

i am moving all these scripts without changing the shebang line to a new machine where the default shell is $ echo $SHELL /bin/bash

Should i worry about this ?

I am guessing there should not be any issue as the shebang line will override the interpreter and use ksh as defined in the scripts and as i want it to be.

Please share your thoughts ..

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Kevin
  • 183
  • 2
  • 11
  • 1
    You're correct: The shebang line is honored on any `execve()` call. Only if your scripts are sourced do you need to care which interpreter they're called from. – Charles Duffy Feb 23 '15 at 19:51
  • Or if the listed interpreter doesn't exist or isn't executable or other oddity. – Etan Reisner Feb 23 '15 at 19:52

3 Answers3

1

The default shell does not affect how scripts are executed (unless you're using a shell that does something very strange).

An executable script with no #! line will be executed with /bin/sh. Actually that doesn't appear to be correct, but in any case you don't have to worry about that.

As long as your scripts start with #!/bin/ksh and you execute them normally, the system will execute them by passing them to /bin/ksh.

One thing you might have to worry about is whether /bin/ksh exists, and if it does, just what it is. On my system (Linux Mint 17), /bin/ksh is a symlink to /etc/alternatives/ksh, which in turn is a symlink to /bin/ksh93.

Scripts with #!/bin/ksh are probably common enough that almost all UNIX-like systems will cater to them, and will install something that behaves like ksh at that location.

Note that what you call the "default shell", specified by $SHELL, is not a system-wide default. It's just the value of a particular environment variable. That variable is set for each user on login based on the shell specified in /etc/passwd or equivalent; thus different users can have different default shells. You can change the value of $SHELL after logging in. The entry in /etc/passwd or equivalent is set when the account is created, and can be changed later. Most systems have a default user shell that's set for new accounts if no shell is specified (for example, most Linux systems user /bin/bash).

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
0

The supposition given is correct: The shebang line is honored on any execve() call. Only if your scripts are sourced (. yourscript or source yourscript) or lack a valid shebang do you need to care which interpreter they're called from.

If this were not true, scripts in non-shell languages wouldn't work as expected (as the Python interpreter, for instance, is never a system's default shell).

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
0

The kernel will use the shebang line to select the appropriate interpreter to use when the script is executed in the default manner, whether it is sh, bash, ksh, expect, python, or whatever. The only real issue to be wary of is scripts written on a system where sh is one specific shell (e.g. bash) that are then moved to another system where sh is a different shell (e.g. dash) since they may use shell features found in the former that do not exist in the latter.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358