Answer the question
In order to leave comments, you need to log in
How can I find out the name of the main script using the included script?
there is script1.sh, script2.sh is connected to it with the help of source
How to find out the name of the first script (script1.sh) in script2.sh using the means of only script2.sh itself?
$0 is of little use in this case, as it displays the name of the internal script:
% cat script1.sh
#!/usr/bin/env zsh
echo Скрипт1="$0"
source /путь/к/script2.sh
%
% cat script2.sh
echo Скрипт2="$0"
%
% ./script1.sh
Скрипт1=./script1.sh
Скрипт2=/путь/к/script2.sh
%
Answer the question
In order to leave comments, you need to log in
so far this is the option:
$ cat script2.sh
local cmdline="$(cat /proc/$$/cmdline)"
echo script1=$(echo ${(V)cmdline} |awk -F'\\^@' '{print $2}')
My launch of script1.sh immediately displays exactly the path to the script with which it was called, but I use bash:
$ cat script1.sh
#!/usr/bin/env bash
echo Скрипт1="$0"
source script2.sh
$ cat script2.sh
echo Скрипт2="$0"
$ ./script1.sh
Скрипт1=./script1.sh
Скрипт2=./script1.sh
$
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question