Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'This may hurt cross-platform scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
This may hurt cross-platform scripts
Authored by: mzs on Nov 11, '09 04:42:23AM

I did a trick with IFS=/ for a long time, starting back with some scripts that I wrote originally for SunOS in '95 that then needed to work in HPUX, AIX, and IRIX as well soon after: Here is an example that I just came-up with from foggy memory:

/bin/sh -c 'progname() {
eval progname=\$$#

progname $0

echo "$progname"' /foo/bar/baz

It worked great. The trick is that eval does not spawn a subshell. A generic 'setter' routine can be written using the same tricks. You might think that you can use set instead of a function, but be wary of dashes. As a side benefit, it prevented people setting IFS breaking my broken shell scripts.

[ Reply to This | # ]