Why do backticks, when used for saving command output, cause an EOF error?

守給你的承諾、 提交于 2019-12-08 03:28:22

问题


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

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

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

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


回答1:


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 <-")

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



来源:https://stackoverflow.com/questions/56634196/why-do-backticks-when-used-for-saving-command-output-cause-an-eof-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!