管道到另一个命令bash

时间:2014-06-03 11:22:28

标签: bash tar gunzip

我似乎无法使我的bash脚本工作,我想将gunzip命令的输出传递给另一个命令,但它不起作用,有人可以帮助我吗?

gunzip命令输出一个tar文件,然后我想使用tar命令放回原始文件。

# let the user choose what they want to Restore
echo -n "Select the file or directory you want to Restore" 
read Chosendata 

echo -e "Starting Restore"

# unziping files
gunzip ${Chosendata} | tar xvf -                        #Here
# end the restore.
echo -e "Restore complete"

1 个答案:

答案 0 :(得分:4)

使用gunzip -c

  -c, --stdout      write on standard output, keep original files unchanged

或仅 tar tar -xzf ${Chosendata}

相关问题