$ cat test.sh
HA=/user/lfs/go/4/entry
LA=${HA/\/go\/4\/entry}
echo $LA
$ sh test.sh
test.sh: 2: test.sh: Bad substitution
$ source test.sh
/user/lfs
source还有这种奇怪的功能,从来没见过呢,哪位大神给解释一下文件第二行是啥意思,
为什么source和bash还有这种奇怪的区别
跪谢
source还有这种奇怪的用法?
-
- 帖子: 14
- 注册时间: 2018-03-09 15:15
- 系统: Ubuntu16.04
-
- 论坛版主
- 帖子: 18279
- 注册时间: 2009-08-04 16:33
Re: source还有这种奇怪的用法?
http://manpages.ubuntu.com/manpages/tru ... .3tcl.html
source - Evaluate a file or resource as a Tcl script
This command takes the contents of the specified file or resource and passes it to the Tcl interpreter as a text script.
The return value from source is the return value of the last command executed in the script.
source - Evaluate a file or resource as a Tcl script
This command takes the contents of the specified file or resource and passes it to the Tcl interpreter as a text script.
The return value from source is the return value of the last command executed in the script.
- lilydjwg
- 论坛版主
- 帖子: 4249
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: source还有这种奇怪的用法?
一点也不奇怪。奇怪的是,没人告诉你 sh 和 bash 不一样吗?
-
- 帖子: 14
- 注册时间: 2018-03-09 15:15
- 系统: Ubuntu16.04
Re: source还有这种奇怪的用法?
查了一下 系统的sh指向的是dash,换成bash就好了lilydjwg 写了:一点也不奇怪。奇怪的是,没人告诉你 sh 和 bash 不一样吗?
但是第二行为什么可以那么用?
- lilydjwg
- 论坛版主
- 帖子: 4249
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: source还有这种奇怪的用法?
因为 bash 就是这样设计的。man bash 然后搜「Parameter Expansion」。longf0720 写了:查了一下 系统的sh指向的是dash,换成bash就好了lilydjwg 写了:一点也不奇怪。奇怪的是,没人告诉你 sh 和 bash 不一样吗?
但是第二行为什么可以那么用?
-
- 帖子: 14
- 注册时间: 2018-03-09 15:15
- 系统: Ubuntu16.04
Re: source还有这种奇怪的用法?
查到了好多参数展开的知识lilydjwg 写了:因为 bash 就是这样设计的。man bash 然后搜「Parameter Expansion」。longf0720 写了:查了一下 系统的sh指向的是dash,换成bash就好了lilydjwg 写了:一点也不奇怪。奇怪的是,没人告诉你 sh 和 bash 不一样吗?
但是第二行为什么可以那么用?