我有有很多的bash脚本echo语句,也是我别名echo到echo -e两个.bash_profile及.bashrc,使新线为语句正常打印一样echo 'Hello\nWorld'的输出应该是
Hello
World
Run Code Online (Sandbox Code Playgroud)
但我得到的输出是
Hello\nWorld
Run Code Online (Sandbox Code Playgroud)
我什至尝试shopt -s expand_aliases在脚本中使用,它没有帮助
我正在运行我的脚本bash /scripts/scriptnm.sh;如果我. /scripts/scriptnm.sh在获得所需的输出时运行它...
我有一个脚本,如下所示......
顶部的一些函数定义,其中之一是......
function err_out
{
trap 'echo "ERROR in $STEP function. EXITING!";exit 1' ERR
#some more messages
exit 1
}
# Main program starts here
trap 'err_out' ERR
#do something
#call some functions
#call cleanup function
#end of script
Run Code Online (Sandbox Code Playgroud)
当函数中发生一些错误时,它们不会传播,并且 err_out 函数不会被调用。
我也尝试过#!/bin/bash -E;这样,当出现错误时,脚本会退出,但我需要的是将错误正确传播到处理程序。