【问题标题】:Use of command sed and echo over a ssh connection [duplicate]通过 ssh 连接使用命令 sed 和 echo [重复]
【发布时间】:2014-07-09 08:16:50
【问题描述】:

我知道有人已经要求类似的东西,但我无法在远程主机中使用该命令。我有 bash:

#!/bin/bash
IMSI="732111030120252"
ssh openbts@192.168.10.12 bash -c " '
sed -i '61,$d' /etc/asterisk/sip.conf   #erase the lines fron 61 to end of the file sip.conf
sed -i '288,$d' /etc/asterisk/extensions.conf
echo "[IMSI$IMSI].(sets)" >> /home/openbts/Desktop/Prueba  #Write that expression inside Prueba (Ignore .)

' "

但是,他正在考虑将 $d() 视为局部变量,而不是 sed 和 echo 命令的一部分。

我发现您可以使用 \\\$d 或 echo 中的所有行,但它们不起作用。

有人有想法吗??谢谢

【问题讨论】:

  • 变量在双引号内展开。将命令放在单引号中,它们不会在本地展开。

标签: linux bash ssh


【解决方案1】:

你需要正确地转义字符串,尤其是$"

ssh openbts@192.168.10.12 "sed -i '61,\$d' /etc/asterisk/sip.conf;
  sed -i '288,\$d' /etc/asterisk/extensions.conf;
  echo \"[IMSI\$IMSI].(sets)\" >> /home/openbts/Desktop/Prueba;"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-25
    • 1970-01-01
    • 2013-06-06
    • 2021-05-26
    • 2015-12-27
    • 2012-05-20
    • 1970-01-01
    • 2018-10-14
    相关资源
    最近更新 更多