由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - sh question: get the file name of a script when started from a dot command
相关主题
Please help: regarding ftp scripting in Windows xp Command prompt为什么需要node.js waterfall,而不是直接call python script
大家programming时怎么命名?请教一下关于各大公司是怎么做测试的
怎么才能在Unix里连续跑10个c写的程序求助:script for commands (转载)
是zsh吗?[合集] Shell script problem?
java + javascript open local file?Call assembly in c++ under linux
Script question这样读多个文件对吗?
弱问bash script, 关于IFS问题[转载] Re: [转载] 这样读多个文件对吗?
有谁对bash script熟悉的,请教一个问题超牛的debug
相关话题的讨论汇总
话题: script话题: command话题: name话题: dot话题: file
进入Programming版参与讨论
1 (共1页)
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 的大作中提到】
: 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
1 (共1页)
进入Programming版参与讨论
相关主题
超牛的debugjava + javascript open local file?
Re: [转载] how would you do this?Script question
perl: how to get the filename from the full path name弱问bash script, 关于IFS问题
How to fire up MFI in C#?有谁对bash script熟悉的,请教一个问题
Please help: regarding ftp scripting in Windows xp Command prompt为什么需要node.js waterfall,而不是直接call python script
大家programming时怎么命名?请教一下关于各大公司是怎么做测试的
怎么才能在Unix里连续跑10个c写的程序求助:script for commands (转载)
是zsh吗?[合集] Shell script problem?
相关话题的讨论汇总
话题: script话题: command话题: name话题: dot话题: file