Creating for loop for tar -tvf doesnt work

hi all,

i have created a for loop, it looks like this -

#!/bin/bash
cd /mnt/local/data/tars
for tar in *
        do

        base=$(basename "$tar")

        "$base" -tvf >> /mnt/local/data/logs/"$base".csv

        done

but i get this error -

./tar_loop.sh: line 8: test1.tar: command not found
./tar_loop.sh: line 8: test2.tar: command not found
./tar_loop.sh: line 8: test3.tar: command not found
./tar_loop.sh: line 8: test4.tar: command not found
./tar_loop.sh: line 8: test.tar: command not found

so in my

cd /mnt/local/data/tars

i have the tar files above ie test1.tar and so on

why am i getting this error

many thanks,

rob

$tar

evaluates to a file name, which is not a valid script or command.
try:

  tar -tvf "$base" >> /mnt/local/data/logs/"$base".csv
1 Like

thanks, it works but that command doesnt make sense,

the command to do manually is -

filename.tar -tvf

why have you put "$base" after the tvf

edit - sorry i had a dumb moment, i figured it out