为什么反引号用于保存命令输出时会导致EOF错误? [英] Why do backticks, when used for saving command output, cause an EOF error?

查看:83
本文介绍了为什么反引号用于保存命令输出时会导致EOF错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遍历一个Clearcase文件列表,以查看文本 Merge<-是否不属于 ct describe

I am looping through a list of clearcase files to see if the text "Merge <-" is not part of the output of ct describe.

我已经尝试过在这一系列的case文件中运行while循环,然后将其附加到另一个文件中(如果它符合我的期望)。下面是我使用的确切逻辑:

I have tried running a while loop on this list of clearcase files then appending it to another file if it meets my desired condition. Below is the exact logic I used:

16 FILTER_LIST=cut -f1 -d'@' branchmerge_versions.txt
17 touch temp.txt
18 echo $FILTER_LIST > temp.txt
19 
20 while read t; do
21    isMerged=`cleartool describe t | grep -e "Merge <-"`
22   if [[ "x$isMerged" == "x" ]]; then
23          echo "$t" >> filesToMerge.txt
24   fi
25 done < temp.txt
26

运行 bash -n 脚本返回了以下错误:

Running bash -n on the script returned these errors:

filter.sh: line 21: unexpected EOF while looking for matching ``'
filter.sh: line 26: syntax error: unexpected end of file

为什么命令反引号会导致意外的EOF错误?

Why would the command backticks lead o an unexpected EOF error?

推荐答案

正如我在 在外壳编程中, $(command)和`command``有什么区别?

As I explained in "What is the difference between $(command) and `command`` in shell programming?"


嵌入式命令替换和/或双引号的使用需要使用反斜杠字符进行仔细的转义。

我们更喜欢$(...)

embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character.
We prefer $( ... )

在您的情况下,请尝试使用

In your case, do try with

isMerged=$(cleartool describe t | grep -e "Merge <-")

但是,如前所述,请首先检查您的内容输入文件 temp.txt

But, as commented, check first the content of your input file temp.txt.

这篇关于为什么反引号用于保存命令输出时会导致EOF错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆