我想创建一个简单的女巫案例,我可以根据用户提示执行功能:
echo Would you like us to perform the option: "(Y|N)"
read inPut
case $inPut in
# echoing a command encapsulated by
# backticks (``) executes the command
"Y") echo 'Starting.....'
donwload_source_code
# depending on the scenario, execute the other option
# or leave as default
"N") echo 'Stopping execution'
exit
esac
但是当我执行脚本时,我收到错误:
Would you like us to perform the option: (Y|N)
n
run.sh: line 27: syntax error near unexpected token `)'
run.sh: line 27: `"N") echo 'Stopping execution''
EMP-SOF-LT099:Genesis Plamen$
道你知道我怎么解决这个问题吗?
答案 0 :(得分:2)
添加;;
#!/bin/bash
echo Would you like us to perform the option: "(Y|N)"
read inPut
case $inPut in
# echoing a command encapsulated by
# backticks (``) executes the command
"Y") echo 'Starting.....'
donwload_source_code
# depending on the scenario, execute the other option
# or leave as default
;;
"N") echo 'Stopping execution'
exit
;;
esac
答案 1 :(得分:2)
多个问题。
;;
构建case
exit
命令在switch-case
构造中放错了,而;;
没有case
。它应该在read
或更高的末尾。echo
有自己的选项可以为用户提示打印消息,可以避免不必要的#!/bin/bash
read -p "Would you like us to perform the option: \"(Y|N)\" " inPut
case $inPut in
# echoing a command encapsulated by
# backticks (``) executes the command
"Y") echo 'Starting.....'
donwload_source_code
;;
# depending on the scenario, execute the other option
# or leave as default
"N") echo 'Stopping execution'
exit
;;
esac
。无错误的脚本
function CMChangeSignal(constant) {
/** take initial value here if it possible and pass it to constan fnt */
var out = constant();
// listen to it
CodemirrorInstance.on('change',function(cMirror){
// get value right from instance
var newValue = cMirror.getValue();
out.set(newValue);
});
return function () {
return out;
}
}