In KornShell (ksh), I have a script that calls a list of scripts. The callee script needs to know its file name, so that it can generate unique configuration (or anything should be unique).
The problem is variable $0 always points to the caller script. For example, we have two scripts:
caller.sh:
. callee.sh
callee.sh:
echo $0
When I execute caller.sh, the callee.sh print "caller.sh", not "callee.sh". So how can I get the script file name of current running script?
The script is running on AIX servers, so bash is not available all the time.
It's because you are sourcing callee.sh, i.e. . callee.sh.
So if you can just execute callee.sh (and you don't need environment variables that are set in callee.sh to be active in caller.sh,) change your caller scritpt to
#!/bin/ksh
callee.sh
I hate to say it, but I think the ksh people would say 'Working as designed'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With