I want to use a program in the shebang, so I create a script named <myscript> with:
#!<mypgm>
I also want to be able to run <mypgm> directly from the command prompt.
<mypgm> args...
So far, no issue.
I want to be able to run <myscript> from the command prompt with arguments.
<myscript> blabla
In turn, the shebang makes <mypgm> being called with the following arguments:
<mypgm> <myscript> blabla
Now, I need to know when <mypgm> <myscript> blabla is called using the shebang, or not:
myscript blabla # uses the shebang
-or-
<mypgm> myscript blabla # directly in the command prompt.
I looked at the environment variables (edit: <=== wrong assertion (¬,¬”) ), at the process table (parent process too) but didn't find any way to make a difference.
The only thing I found so far is:
grep nonvoluntary_ctxt_switches /proc/$$/status
When this line is just after the shebang, the value is often 2 (sometimes 3) when called through the shebang, and 1 (sometimes 2) with the direct call. Being unstable and dependent on process scheduling (the number of times the process was taken off from its CPUs), I am wondering if anybody here might have a better solution.
myscript blabla
andmypgm myscript blabla
for you? How do you distinguish betweenmypgm myscript blabla
andmypgm otherargs
? I’m trying to understand what you’d do with the information you’re asking for, once you have it.calc myscript blah
, how are you going to differenciate betweencalc PI
wherePI
is a script, andcalc PI + 1
? (This is why most tools use an option for scripts, e.g.awk -f myscript
.)