在bash脚本中运行几个命令

时间:2018-11-12 10:40:32

标签: bash scripting

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

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 可以运行终端中的所有内容(逐步),那么我想一次全部运行,您有什么建议吗?

1 个答案:

答案 0 :(得分:2)

问题是如果外壳不是交互式的,则别名不会扩展:

  

别名::除非外壳程序不是交互式的,否则别名不会扩展,除非使用expand_aliases设置了shopt外壳程序选项。

     

来源:man bash

在脚本中添加以下内容:

shopt -s expand_aliases
相关问题