skarnet / execline

The execline scripting language
https://skarnet.org/software/execline/
ISC License
149 stars 19 forks source link

#!/bin/execlineb -P doesn't set $0 #7

Closed hongkongkiwi closed 3 years ago

hongkongkiwi commented 3 years ago

I've got some scripts which don't take any arguments (hence the -P), but I would like to know the name of the executing script which is normally set in 0 env. Also, -S0 is the same problem.

Here's my script:

#!/bin/execlineb
backtick -E scriptdir {
  importas arg0 0
  dirname "$arg0"
}
envfile "/etc/s6/sv/${scriptdir}/conf"
......

But I found that when I use the -P tag, no variables (including 0) are defined. I would expect in either case, 0 to contain the name of the script even when no variables are being passed in.

skarnet commented 3 years ago

-P explicitly disables putting arguments into the environment, including the script's name. -S0 also disables putting arguments into the environment, but substitutes $0 in the script directly. What you want is:

#!/bin/execlineb -S0
backtick -E scriptdir { dirname $0 }
envfile /etc/s6/sv/${scriptdir}/conf
...