سؤال

Hi I am working with Bash Script and i have difficulty on extracting a tar file and inside of the tar file is another tar file . Please see below code and please provide me with feedback because the only thing that the code do will just extract the the first tar file and remove it.

#!/bin/bash

output=$(df -h)
bundle=$(awk -F = '{print $2}' config.txt)
bundlename=$(echo $bundle | awk -F / '{print $11}')  
echo "$output"

wget $bundle
echo "$bundlename"
tar -xzvf "$bundlename"
rm -vf "$bundlename"

My question is what is the right way/code to extract all the tar file inside the tar file ?.

هل كانت مفيدة؟

المحلول

you can pipe the output of the tar extract to the tar command again to run it. for example:

tar -xvf xyz.tar |grep '\.tar$' | xargs -n 1 | tar -xvf

but this will only extract one level tar files, if the extracted tar contains another tar, then again you will have to pipe it. I hope you get the point.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top