0

I wonder why this command:

FILE=`file /usr/bin/java | tr -d \`\' | awk '{print $5}'`

Results in this error message:

bash: command substitution: line 1: unexpected EOF while looking for matching ``'
bash: command substitution: line 2: syntax error: unexpected end of file

If I run the previous command without assigning it to a variable, it works as expected:

$ file /usr/bin/java | tr -d \`\' | awk '{print $5}'
/etc/alternatives/java

Does anyone know why this happens and how can I successfully assign the output value to a variable?

Note: for the curious, I'm trying to find the pointed path to a binary file from a symbolic link, so I can find out if it is a 32 or 64 bits file (in a generic way, not using something like java -version)

Note 2: I've tried removing quotes with sed instead of tr, but it returns the same error

Thank you very much in advance, regards...

Nacho

0

1 Answer 1

5

I think it's because you enclosed the commands inside back-ticks. Use $() instead of backticks.

FILE=$(file /usr/bin/java | tr -d \`\' | awk '{print $5}')
Sign up to request clarification or add additional context in comments.

3 Comments

Not the back-ticks are the problem of the original code but the lack of escaping inside them. The command line included in back ticks contains two backslashes and they need to be escaped but they are not.
Thank you very much Avinash Raj! This solved my problem
@axiac you're right, escaping it like this works fine too FILE=`file /usr/bin/java | tr -d \\`\' | awk '{print $5}'`

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.