我正在解除.tar.gz文件並將輸出重定向到變量。但是這樣做會給我一個錯誤。將tar命令的輸出重定向到shell腳本中的變量
old_file =$(tar -tvzf $node | head -2 | tail -1 | cut -f4 -d "/")
錯誤:
old_file: command not found
但是,如果在終端運行此命令我得到一些輸出。
無法弄清楚,如果tar文件重定向工作或沒有?
我正在解除.tar.gz文件並將輸出重定向到變量。但是這樣做會給我一個錯誤。將tar命令的輸出重定向到shell腳本中的變量
old_file =$(tar -tvzf $node | head -2 | tail -1 | cut -f4 -d "/")
錯誤:
old_file: command not found
但是,如果在終端運行此命令我得到一些輸出。
無法弄清楚,如果tar文件重定向工作或沒有?
應該是old_file=$(some cmd)
。變量和'='之間沒有空格。
你可以試試這個;
old_file =$(tar -tvzf $node | head -2 | tail -1 | cut -f3 -d "/")
例如;
tar -tvzf $ node |頭-2 |尾巴-1輸出是這樣的;
-rw-rw-r-- user/user 2 2016-11-07 12:10 yourfile/php.png
如果分隔符是「/」,則切割字段如下所示;
字段1是-rw-rw-r-- user
字段2是user 2 2016-11-07 12:10 yourfile
場3是php.png