Perhaps the Solaris ksh is newer, or on that system it has been fudged to use SHLVL.
Here's how to fudge it. In your .profile, add the line:
Code:
export ENV="$HOME/.ksh_shlvl"
Then create the file $HOME/.ksh_shlvl and put this in it:
Code:
if [ "$SHLVL" = "" ]; then
SHLVL=1
else
let SHLVL+=1
fi
If you want it system-wide, you can put the ENV in the /etc/profile of course, and have the location of .ksh_shlvl somewhere else, e.g. /etc/ksh_shlvl.
Caveats:
1. The first shell you open has to be a login shell. All subsequent shells will inhert the ENV value as long as you exported it in the first shell. Therefore this might not work in scripts unless you explicitly set the ENV value, but I
think all shells you start after re-logging into X (or the console) should have it. I'm assuming you use ksh as your interactive shell here. Be careful about cron jobs - you don't get the /etc/profile or the local .profile executed in cron shells.
2. You can't use your ENV variable for anything else. If you need it for something else, you;ll have to handle the SHLVL thing yourself.
3. Forgetting to copy that weird .ksh_shlvl file to a new system may break your scripts. Fudges like this invariably lead to annoying problems.
4. If someone annoyingly sets SHLVL to a non-integer, you're going to get annoying errors.