moo*_*ara 6 regex unix shell sh
我正在为没有bash的基于unix的有限微内核编写shell脚本!/ bin / sh由于某些原因无法运行以下行。
if [[ `uname` =~ (QNX|qnx) ]]; then
read -p "what is the dev prefix to use? " dev_prefix
if [[ $dev_prefix =~ ^[a-z0-9_-]+@[a-z0-9_-"."]+:.*$ ]]; then
Run Code Online (Sandbox Code Playgroud)
对于第一行和第三行,它抱怨缺少表达式运算符,而对于第二行,它说没有协同处理!谁能阐明/ bin / bash和/ bin / sh脚本之间的区别?
您可以在中使用此等效脚本/bin/sh:
if uname | grep -Eq '(QNX|qnx)'; then
printf "what is the dev prefix to use? "
read dev_prefix
if echo "$dev_prefix" | grep -Eq '^[a-z0-9_-]+@[a-z0-9_-"."]+:'; then
...
fi
fi
Run Code Online (Sandbox Code Playgroud)