1

I am trying to store the output from a command in Bash in a variable, but instead of storing the output it is being interpreted as a command and run. That is not what I want.

tmp="$($line | awk '{print $1}')" This runs the output from awk as a command.

echo $line | awk '{print $1}' This prints out the output I want to store in the variable.

How can I get the output from the second line stored in a variable?

2 Answers 2

3

You're looking for this:

tmp=$(echo "$line" | awk '{print $1}')

But that's a Useless Use of Echo. Use a here-string instead:

tmp=$(awk '{print $1}' <<< "$line")
Sign up to request clarification or add additional context in comments.

Comments

0

This should work

var=`echo $line | awk '{print $1}'`

With the backticks

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.