我在bash脚本中编写命令: -
${SSH} ${USER}@${HOST} mkdir -p ${DEST_LOG_DIR};
但是在调试流程中,我得到:
+ 'ssh -o StrictHostKeyChecking=no' -i xxxxx.pem user@host 'mkdir -p test"
./test.sh: line 454: ssh -o StrictHostKeyChecking=no: command not found
可变的SSH定义为
SSH="ssh -o StrictHostKeyChecking=no"
为什么它会给我这个错误?
答案 0 :(得分:2)
"I'm trying to put a command in a variable, but the complex cases always fail!"
SSH=(ssh -o StrictHostKeyChecking=no)
...
"${SSH[@]}" ...
答案 1 :(得分:-1)
您无法执行此类命令。你需要在这里使用eval:
eval "${SSH} ${USER}@${HOST} mkdir -p ${DEST_LOG_DIR}"
示例:强>
s="ls -w"
${s}
-bash: ls -w: command not found
eval ${s}
file1 file2