[英]What is the difference of running commands in terminal and shell script?
I want to check if tmux alias exists, when I run command in terminal: 在终端中运行命令时,我想检查tmux别名是否存在:
$ type -t tmux
the result is 结果是
$ alias
But when I put "type -t tmux" in a shell script and run, the result is 但是,当我将“ type -t tmux”放入外壳脚本并运行时,结果是
$ ./test.sh
$ file
Why the result is different ? 为什么结果不同?
My test.sh is: 我的test.sh是:
#!/usr/bin/env bash
set -e
type -t tmux
Any aliases defined in .bash_profile
should be read and respected by tmux, but does not read anything in .bashrc
. tmux应该读取并尊重.bash_profile
定义的任何别名,但.bashrc
中不读取任何别名。
Invoking test.sh is a sub-process, and does not use environment from current process unless you source it source test.sh
but that also allows that script to modify current environment. 调用test.sh是一个子过程,除非您从source test.sh
环境,否则不会使用当前过程中的环境,但这也允许该脚本修改当前环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.