I want to use a program in the shebang, so I create a script named <myscript> with:
I also want to be able to run <mypgm> directly from the command prompt.
So far, no issue.
I want to be able to run <myscript> from the command prompt with arguments.
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.
mypgm myscript blablafor you? How do you distinguish between
mypgm myscript blablaand
mypgm 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 between
PIis a script, and
calc PI + 1? (This is why most tools use an option for scripts, e.g.
awk -f myscript.)