Santosh Sahu Santosh Sahu - 1 year ago 88
Bash Question

Redirect output of tar command to a variable in shell script

I am untaring a .tar.gz file and redirecting the output to a variable. But it gives me an error while doing this operation.

old_file =$(tar -tvzf $node | head -2 | tail -1 | cut -f4 -d "/")


old_file: command not found

But if run this command in terminal I am getting some output.

Unable to figure out, if tar file redirection works or not?

Answer Source

Should be old_file=$(some cmd). No space between variable and '='.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download