【发布时间】:2015-10-28 15:42:39
【问题描述】:
我在 UNIX 中创建了一个别名,正则表达式在其中产生了问题。
我的意图是使用别名作为_enable -input,参数应该用“-”传递。
没有找到问题所在。
别名是
alias _enable="function _enable() { [[ $1 =~ ^- ]] || { echo \"Use hyphen (-) before nodes.\"; return 1; } ; [[ $# = 1 ]] && { NODE=`echo ${1##*-}`; } || { NODE=\"\"; } ; $HOME/bin/command --command=enable --node=$NODE; }; _enable $1;"
实际输出为:
SS-04:~ # _enable 1
-bash: conditional binary operator expected
-bash: syntax error near `^-'
【问题讨论】:
-
如果只是在函数内部去掉连字符,为什么还要在参数中使用连字符?