【发布时间】:2017-04-06 11:10:45
【问题描述】:
我的 bashrc 文件中的第一件事是这个表达式:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
有人能解释一下这是什么意思吗?
所有这些符号都很难用 google 搜索,而且没有与 bash 等效的 Haskell “hoogle”,因此我可以搜索符号表达式。
预期的行为似乎与此类似。
nonsourced=0;
# if sourced,
if [[ "$0" == "$BASH_SOURCE" ]]; then
nonsourced=1;
else
nonsourced=0;
fi
echo "nonsourced? $nonsourced";
case $- in
*i*)
# this case is entered if "$-" contains "i".
if [[ "$nonsourced" -eq "0" ]]; then
echo "1. " "$-";
fi
;; # leave case?
*) # this case is entered in all other cases.
if [[ "$nonsourced" -eq "0" ]]; then
echo "2. " "$-";
return
else
# cannot return from nonsourced, use exit.
echo "avoided return from nonsourced #2";
exit 0;
fi
;; # leave case?
esac
echo "3";
【问题讨论】:
-
*)是“默认”,一个有趣的链接:linux.org/threads/case-statement-in-bash-scripts.5602(我搜索了“bash case asterisk”) -
您可以尝试使用 symbolhound.com 搜索包含符号的字符串。
-
为什么需要谷歌?你不知道 bash 手册在哪里吗? gnu.org/software/bash/manual/html_node/index.html
-
从函数外部使用return不是无效吗?这部分代码在函数之外;它可能是来源,但假设这是错误的。
-
您无需搜索任何内容。在你的 shell 中输入
man bash,保持冷静并开始阅读。一切都在那里解释。
标签: bash