I am trying to unzip bzip file using bash this way
tmp1 = #(bzcat all.tbz)
echo tmp1 | tar x
But this fails with
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
But if I do this
bzcat all.tbz | tar x
and that works
What is the problem with my earlier way.
Thanks!
You have numerous syntax mistakes.
tmp1=$(bzcat all.tbz)
echo "$tmp1" | tar x
=
.$(...)
to execute a command and substitute its output.$
before the variable name when echoing it."
around the variable to prevent word splitting and wildcard expansion of the result.But this most likely still won't work because tar files contain null bytes, and bash variables can't hold this character (it's the C string terminator).
If you just want to capture the error message if there's a failure, you can do:
tmp1=$((bzcat all.tbz | tar x) 2>&1)
if [ ! -z "$tmp1" ]
then echo "$tmp1"
fi