【问题标题】:running several comands in a bash script [duplicate]在 bash 脚本中运行多个命令 [重复]
【发布时间】:2018-11-12 18:51:22
【问题描述】:

我想按以下顺序运行一些命令:

HEADAS=/home/warano/HEASoft/heasoft-6.24/x86_64-pc-linux-gnu-libc2.27
export HEADAS 
alias heainit=". $HEADAS/headas-init.sh" 
heainit
CALDB=/home/warano/NUSTAR/caldb
export CALDB 
source $CALDB/software/tools/caldbinit.sh 

我将所有这些都放在一个名为 run-nu_tools.sh 的脚本中,但它不起作用,所以我得到了以下输出:

./run-nu_tools.sh: line 6: heainit: command not found

但是 heainit 如果一个人在终端中运行所有内容(逐步),所以我想一次运行所有内容,你有什么提示吗?

【问题讨论】:

  • 别名很烂。使用函数。
  • 这根本没有帮助。
  • 为什么说它没有帮助?为什么不想使用函数?为什么要使用别名?如果你仍然使用一个函数会发生什么?

标签: bash scripting


【解决方案1】:

问题是如果 shell 不是交互式的,别名不会被扩展:

别名:除非使用shopt 设置了expand_aliases shell 选项,否则当shell 不交互时不会扩展别名。

来源:man bash

将以下内容添加到您的脚本中:

shopt -s expand_aliases

【讨论】:

猜你喜欢
  • 2014-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-08
  • 1970-01-01
  • 1970-01-01
  • 2014-12-02
  • 2015-04-11
相关资源
最近更新 更多