1

What is difference b/w these two command and output variable:

output=($(command))

And

output=`command`
0

2 Answers 2

4

In the first case, the resulting variable is an array, with the number of elements depending on the output of your command. In the second case, it is a scalar containing the complete result value. This difference is only due to the extra outer brackets in the first case.

Try it with, for example, the ls command to see the difference.

Additionally, the $(command) form has superseded the 'command' form for command substitution.

Sign up to request clarification or add additional context in comments.

Comments

1

The only difference is that $() calls can be nested, AFAIR (okay, backticks can be nested too, but you have to escape all nested backticks, so $() provides nicer syntax).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.