Contents
How do you get the name of the script inside the shell script in Unix?
- Get the parent PID of running process from grep PPid /proc/self/status | awk ‘{print $2}
- Find out it’s executable name ls /proc//exe.
- Use readlink to print out the name of above softlink readlink /proc//exe.
How do I find the name of a function in Linux?
You can use ${FUNCNAME[0]} in bash to get the function name. An array variable containing the names of all shell functions currently in the execution call stack. The element with index 0 is the name of any currently-executing shell function.
Which variable contains the name of the script?
The underscore variable is set at shell startup and contains the absolute file name of the shell or script being executed as passed in the argument list.
How to determine the path to a shell script?
The element with index 0 is the name of any currently-executing shell function. The bottom-most element (the one with the highest index) is “main”. This variable exists only when a shell function is executing. Assignments to FUNCNAME have no effect and return an error status.
How to get the name of the script?
Based on @J.L.answer, with more in depth explanations (the only one command that works for me ( linux )) : in /proc/, you have some dirs with the pid of each process ( linux ). Then, if you cat /proc/$PPID/comm, you echo the command name of the PID
How to find the name of a function in Bash?
An array variable containing the names of all shell functions currently in the execution call stack. The element with index 0 is the name of any currently-executing shell function. The bottom-most element (the one with the highest index) is “main”. This variable exists only when a shell function is executing.
How to get the PID of a shell script?
in /proc/, you have some dirs with the pid of each process ( linux ). Then, if you cat /proc/$PPID/comm, you echo the command name of the PID.