gpt4 book ai didi

linux - set -e 覆盖 bash 脚本中的参数变量($@)

转载 作者:太空狗 更新时间:2023-10-29 11:46:39 24 4
gpt4 key购买 nike

我有一个脚本test.sh

#/!bin/bash
set -e
trap errorhandler ERR

errorhandler(){
status=$?
trap - ERR
exit $status
}

echo "$@"

exit 0

当我调用 sh test.sh 'Hey' 时,它将打印 -e 而不是 Hey

我的解决方法是用反引号包围 set -e 但不知道它是否仍能按预期工作

另一种解决方法是将它存储在第一行的变量中,但出于一个明显的原因(处理错误),我希望在第一行中使用 set -e

有没有聪明的方法来做到这一点?比如“嘿,别碰我的 $@”命令。

最佳答案

明白了! -e–e 注意破折号。第一个是正确的。

学过的知识。不要直接从 html 复制代码。

关于linux - set -e 覆盖 bash 脚本中的参数变量($@),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9629543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com