如果外壳程序功能需要特定的-e / + e设置才能起作用,是否可以在本地设置该设置,然后在退出该功能之前将其恢复为以前的设置?
myfunction()
{
# Query here if -e is set and remember in a variable?
# Or push the settings to then pop at the end of the function?
set +e
dosomething
doanotherthing
# Restore -e/+e as appropriate, don't just do unconditional set -e
}
$-
也可以使用/bin/sh
,您可能不需要bashisms来解析它,只需使用例如case
提供以下内容的globbing