分页: 1 / 1
$0能显示程序名吗?
发表于 : 2009-04-27 7:44
由 freesky3555
资料上说$0显示程序名,可实际只出来是bash而不是程序名
Re: $0能显示程序名吗?
发表于 : 2009-04-27 8:39
由 eexpress
自己测试,对了就对了。
Re: $0能显示程序名吗?
发表于 : 2009-05-09 14:02
由 petrele.chen
freesky3555 写了:资料上说$0显示程序名,可实际只出来是bash而不是程序名
用basename吧
在脚本里放上echo `basename`试试看
Re: $0能显示程序名吗?
发表于 : 2009-05-09 14:37
由 xiooli
你要把这个放脚本里面才行。直接在bash里面执行当然是bash咯。
Re: $0能显示程序名吗?
发表于 : 2009-05-09 16:38
由 freesky3555
xiooli 写了:你要把这个放脚本里面才行。直接在bash里面执行当然是bash咯。
在ubuntu终端中怎么处理也是bash
Re: $0能显示程序名吗?
发表于 : 2009-05-11 18:39
由 freesky3555
举一例,如有以下文件:testfile
代码: 全选
# echo filename
echo $0 is this programe name.
# . testfile
/bin/bash is this programe name.
#sh testfile
testfile is this programe name.
Re: $0能显示程序名吗?
发表于 : 2009-05-11 22:51
由 aerofox
freesky3555 写了:举一例,如有以下文件:testfile
代码: 全选
# echo filename
echo $0 is this programe name.
# . testfile
/bin/bash is this programe name.
#sh testfile
testfile is this programe name.
举这个例子是证明你已经明白了吗?
Re: $0能显示程序名吗?
发表于 : 2009-05-12 23:46
由 freesky3555
Re: $0能显示程序名吗?
发表于 : 2009-05-12 23:49
由 hubert_star
.
./
sh
三者的区别
第一个点,是后面跟一个空格的
Re: $0能显示程序名吗?
发表于 : 2009-05-12 23:51
由 hubert_star
算了,告诉你吧
. xxx.sh 不是去当作一个程序执行这个脚本
./xxx.sh 才是
sh xxx.sh 也行,与./xxx.sh的区别是./xxx.sh是可执行权限,而这句不必是
Re: $0能显示程序名吗?
发表于 : 2009-05-12 23:56
由 BigSnake.NET
. 就是 source
Re: $0能显示程序名吗?
发表于 : 2009-05-13 16:03
由 freesky3555
各位是一般是怎么执行脚步的?是source还是chmod +x,还是sh?
Re: $0能显示程序名吗?
发表于 : 2009-05-13 20:51
由 archangelwin
是不是
chmod +x XXX
./XXX
呢?

Re: $0能显示程序名吗?
发表于 : 2009-05-13 22:08
由 aerofox
一般情况下 chmod +x 后以脚本文件名作为命令执行,当脚本用于修改当前 shell 的环境时用点命令执行(即 source)。