سؤال

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'
هل كانت مفيدة؟

المحلول

I try this way and answer :

cd "$a"
for f in $b'_*.gz'
do
   tar cf $a/$b'.tar' $f
done

نصائح أخرى

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.

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