如何避免将变量传递给 SSH 时出现“错误的转义字符”?

如何避免将变量传递给 SSH 时出现“错误的转义字符”?

我有一个从命令行传递的字符串变量,我想在 SSH 中使用它。

#!/bin/bash
while getopts ":b:e:" arg; do
  case "${arg}" in
    b) b="$OPTARG";;
    e) e="$OPTARG";;
  esac
done

echo "locally using $b and $e"

ssh @myhost "$b $e" << 'EOF'

echo "Remotely using $b and $e"

EOF

输出:

locally using 06-30-20-18-10 and 06-30-20-23-59
Bad escape character '06-30-20-23-59'

运行:bash file.sh -b 06-30-20-18-10 -e 06-30-20-23-59

如何避免错误的转义字符并远程使用变量?

相关内容