views:

22

answers:

2

I manage a large number of shell (ksh) scripts on server A. Each script begins with the line...

#!/usr/bin/ksh

When I deploy to machine B, C, and D I frequently need to use a different shell such as /bin/ksh, /usr/local/bin/ksh or even /usr/dt/bin/ksh. Assume I am unable to install a new version of ksh and I am unable to create links in any protected directories such as /usr/local/bin. At the moment I have a sed script which modifies all the scripts but I would prefer not to do this. I would like to standardize the header so that it no longer needs to be changed from server to server. I don't mind using something like

#!~/ksh

And creating a link which is on every server but I have had problems with finding home using "~" in the past when using rsh (maybe is was ssh) to call a script (AIX specifically I think). Another option might be to create a link in my home directory and ensuring that it is first in my PATH, and simply using

#!ksh

Looking for a good solution. Thanks.

A: 
#! /usr/bin/env ksh

will use whatever ksh is in the user's path.

rettops
Is there a way to modify the default path when the script is called from cron? .profile is not read at this point, in many cases the wrong ksh is in my default path
Ethan Post
+1  A: 

As rettops noted, you can use:

#!/usr/bin/env ksh

This will likely work for you. However, there can be some drawbacks. See Wikipedia on Shebang for a fairly thorough discussion.

Mark Eirich
OK thanks. The Wikipedia article was helpful, I see this is not a "solved" problem. I have some ideas.
Ethan Post