bash中命令未找到错误

时间:2013-11-17 12:47:12

标签: bash

我在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" 

为什么它会给我这个错误?

2 个答案:

答案 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