I have a file named input.txt with this contents:
…
FILE "Edie – Realities.txt" TXT
…
And I want to read it, then strip filename path from line that starts with FILE, and check if it exists, so:
[ -f $(cat input.txt | grep FILE | grep -o "\".*\"") ] && echo "exist" || echo "does not exist"
but this outputs:
[: too many arguments
does not exist
If I run:
echo $(cat input.txt | grep FILE | grep -o "\".*\"")
I get what I expected:
"Edie - Realities.txt"
So why is this, or how can I solve this problem?
Best Answer
$(...)
is evidently passing"Edie
,-
, andRealities.txt"
as separate arguments. You need to quote$(...)
like any other$variable
, and you probably want to remove the"
s.