j******n 发帖数: 271 | 1 While a sh script can access its own file name through $0, yet when a
script is run from a dot command, $0 is not the name of the script, but
rather the name of the command or script that runs the dot command. So the
question: how does the script find its own file name when it is run from a
dot command?
Example:
$ cat ./z
echo $0
$ ./z
./z
$ . ./z
bash | X****r 发帖数: 3557 | 2 ${BASH_SOURCE}
(assuming you are using bash, as the '.' built-in indicates)
the
a
【在 j******n 的大作中提到】![](/moin_static193/solenoid/img/up.png) : While a sh script can access its own file name through $0, yet when a : script is run from a dot command, $0 is not the name of the script, but : rather the name of the command or script that runs the dot command. So the : question: how does the script find its own file name when it is run from a : dot command? : Example: : $ cat ./z : echo $0 : $ ./z : ./z
| l*******G 发帖数: 1191 | 3 The following works :
#!/bin/bash
filename=`basename $0`
echo "script name is:" $filename |
|