3

I would like to create a .tar file from all .gz files in $a/$b and delete those files afterwards.

I have come up with the following code but it's not working:

cd "$a"
#tar cf $a/$b'.tar' "$b_sql.gz" "$b_moh.tar.gz" 
tar cf $a/$b'.tar' $b'_*.gz'
gzip $a/$b'.tar'
rm -f $b'_*.gz'
Adrian Frühwirth
  • 42,970
  • 10
  • 60
  • 71
Samira Khorshidi
  • 963
  • 1
  • 9
  • 29

2 Answers2

3

I try this way and answer :

cd "$a"
for f in $b'_*.gz'
do
   tar cf $a/$b'.tar' $f
done
Samira Khorshidi
  • 963
  • 1
  • 9
  • 29
2

The problem is with your use of * within a string. It's treating * as a character rather than doing the glob in the shell.

You can test this yourself by running ls *.gz and then ls '*.gz' within your shell.

Adrian Frühwirth
  • 42,970
  • 10
  • 60
  • 71
Lucas Holt
  • 3,826
  • 1
  • 32
  • 41