linux - 使用多个引号时出错

标签 linux bash shell quotes

<分区>

我写过:

ssh $ip_address "grep -i 20-10-2018 | awk -F "," '{print $2",""open_"$5}' 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 $2",open_"$5 }' |  # 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" 是什么意思。我原封不动地保留了那部分。


查看这篇文章以了解如何引用 awk 命令:

另一篇关于在 shell 中使用引号的有用帖子:

关于linux - 使用多个引号时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49664704/

相关文章:

linux - 将 tar 文件复制到另一个目录,同时保留原始文件名

linux - 假设我正在运行一个名为 RTP.sh 的脚本并且它停止了。是否有任何命令可以知道特定进程何时在 ubuntu 中停止?

linux - 如何在 gcc 版本之间切换以在 manjaro linux 上使用 cudnn 5 加速(cuda 7.5)构建 torch7 或 caffe?

bash - awk:从完整路径中提取文件名

shell - 从 shell 脚本中的变量中删除非 ascii 字符

php - 如何解决 PHP 版本升级 “The apache2 configtest failed.” 后出现的此错误?

bash - 在此Docker compose命令中 “--”是什么意思?

r - 从 R 中调用 bash

bash - 如何将额外的分隔符添加到 CSV 文件的末尾,发现某些分隔符丢失了?

在 Golang 中使用输入重定向来排除差异