当我在终端中运行命令时,我想检查 tmux 别名是否存在:
$ type -t tmux
结果是
$ alias
但是当我将“type -t tmux”放入 shell 脚本并运行时,结果是
$ ./test.sh
$ file
为什么结果不同?
我的 test.sh 是:
#!/usr/bin/env bash
set -e
type -t tmux
最佳答案
tmux 应该读取并遵守 .bash_profile
中定义的任何别名,但不会读取 .bashrc
中的任何内容。
调用 test.sh 是一个子进程,除非您获取它,否则不会使用当前进程中的环境
source test.sh
但这也允许该脚本修改当前环境。
关于linux - 终端和shell脚本中运行命令有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26859281/