0

I am trying to create a script that automates one line of command which is used for archiving selected files to tape and creating a text file with the archived files. a and b are inputs and in the example below and I define them as 03 and 15.

a=03

b=15

tar -cvf /dev/tapedrive file_03 file_04 file_05 .........file_15 > /text_files/backup_file_03-15.txt

the script I came up with is below,

#! /bin/bash

a=03
b=15

for (( c=$a; c<=$b; c++ ))
$tt=" ";
do
    if[ ! $c $a ]
    then
        $c="0$c"
    fi
    $tt .= " file_".$c.""
end    

echo tar -cvf /dev/tapedrive $tt > /text_files/backup_file_$a-$b.txt

done

it's 'echo' for now instead of 'do' to make sure I get the right final command line. I am receiving the error

jag5v1.sh: line 9: syntax error near unexpected token `$tt=" "'
jag5v1.sh: line 9: `$tt=" ";'

I would appreciate any input. Thanks!

2 Answers 2

2

It seems that all you need to say is:

a=03
b=15
echo tar -cvf /dev/tapedrive $(seq -f 'file_%02g' $a $b) > /text_files/backup_file_$a-$b.txt
Sign up to request clarification or add additional context in comments.

1 Comment

This is more elegant.
1

I have corrected your code. Try this -

#! /bin/bash
a=3
b=15
tt=' ';

for c in $(seq $a $b);
do
    if [ $c -le 9 ]
    then
    c="0"$c
    fi
    tt=$tt" file_"$c
done
echo tar -cvf /dev/tapedrive $tt > /text_files/backup_file_0$a-$b.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.