linux - 终端和shell脚本中运行命令有什么区别?

标签 linux bash ubuntu

当我在终端中运行命令时,我想检查 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/

相关文章:

linux - 在 unix bash 脚本中组织代码

bash - 解析ip :port from a text file的shell脚本

bash - 确保一次只运行一个 shell 脚本实例的快捷方式

linux - 如何复制文件/目录而不更改其属性

linux - 当新文件到达供应商时,bash 文件 cron 作业出现问题

linux - Linux 中的进程控制 block

linux - 在 Linux 机器上运行 whois -h 时识别 IP 地址

linux - 内核模块无法链接 - 未找到符号 mutex_lock_nested

ubuntu - imagemagick 构建每 A4 页两张图像的文档

Rstudio 服务器找不到 R 安装的正确位置 (ubuntu)