Let's assume I have 3 shell scripts:
script_1.sh
#!/bin/bash
./script_3.sh
script_2.sh
#!/bin/bash
./script_3.sh
the problem is that in script_3.sh
I want to know the name of the caller script.
so that I can respond differently to each caller I support
please don't assume I'm asking about $0
cause $0
will echo script_3
every time no matter who is the caller
here is an example input with expected output
./script_1.sh
should echo script_1
./script_2.sh
should echo script_2
./script_3.sh
should echo user_name or root or anything to distinguish between the 3 cases
?
Is that possible? and if possible, how can it be done?
this is going to be added to a rm
modified script... so when I call rm
it do something and when git
or any other CLI tool use rm
it is not affected by the modification
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…