0

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 "/")

Error:

 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?

Santosh Sahu
  • 2,134
  • 6
  • 27
  • 51

2 Answers2

1

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

nopasara
  • 538
  • 3
  • 10
0

could you try this;

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

Eg;

tar -tvzf $node | head -2 | tail -1 output is something like this;

-rw-rw-r-- user/user     2 2016-11-07 12:10 yourfile/php.png

cut fields are as below, if delimiter is "/";

field 1 is -rw-rw-r-- user

field 2 is user 2 2016-11-07 12:10 yourfile

field 3 is php.png

Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24