简体   繁体   English

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

[英]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.

相关问题 在交互式shell和Linux终端(ubuntu 13)中运行python脚本有什么区别? - What's the difference between running python script in interactive shell and in Terminal of Linux(ubuntu 13)? 这两个用于运行Shell脚本的命令有什么区别? - What is the difference between these two commands which are used to run shell script? 命令在Linux终端中有效,但在Shell脚本中无效 - commands work in linux terminal but not in shell script 将命令输出回显到终端的 shell 脚本 - A shell script that echo’s the commands output to the terminal ansible 脚本“SHELL”与在 ubuntu 机器 20.04 EC2 上直接运行 Shell 命令的细微差别? - The subtle difference in an ansible script "SHELL" and the directly running Shell commands on an ubuntu machine 20.04 EC2? 从python脚本运行终端命令(Linux) - Running terminal commands from python script (Linux) Shell脚本:执行2条命令并保持第一次运行 - Shell script: execute 2 commands and keep first running 使用PHP脚本运行Shell命令 - Running shell commands using PHP script 在终端中运行的命令在Shell脚本中不起作用 - Command running in terminal does not work in shell script 使用shell脚本在终端中顺序执行多个命令 - Execute multiple commands sequentially in terminal using shell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM