使用多个引号时出错

Error while using multiple quotes

我写了:

ssh $ip_address "grep -i 20-10-2018 | awk -F "," '{print ",""open_"}' result.csv" | while read line
do
        echo $Date":00:00",$line
done

这是抛出这个错误:

awk: {print ,open_} awk: ^ syntax error

有人能帮忙吗?

使用 heredoc run your commands over ssh:

ssh "$ip_address" << 'EOF'                 # shell will pass the heredoc as is to ssh because the end marker EOF is in quotes
    grep -i 20-10-2018 result.csv |        # I guess you meant to pass result.csv to grep, rather than awk
    awk -F "," '{ print ",open_" }' |  # good to put the parts of the pipeline on different lines for better readability
    while read line; do
      echo $Date":00:00",$line             # not sure what you mean by $Date here - probably $(date)?
    done
EOF

我不确定你所说的 echo $Date":00:00" 是什么意思。我把那部分原封不动地留下了。


请参阅此 post 以了解如何引用 awk 命令:

另一个有用的 post 关于在 shell 中使用引号:

  • When to wrap quotes around a shell variable?

你在单引号里面写双引号是错误的。任何代码在单引号之后先写双引号。