in reply to Re: Reliability on $0
in thread Reliability on $0
If it's the case, simply test if -f $0: if true, you're running a script, otherwise it's one-liner.
Most certainly not! You are already assuming that a file with the name -e can exist (otherwise, your proposed test would be pointless). But the existance of a file named -e doesn't prohibit me from executing perl -e.
But there are other reasons it might fail. The program may have dropped its priviledges, and it now can now longer read the directory the script resides in, so -f would return false. Or the script may have disappeared, or it may have been moved between the start of the program, and the execution of the -f test.
Furthermore, beside the magical value -e, there's also the magical value -, when the program is gotton from STDIN.
$ echo 'print $0' | perl -l -
|
|---|