0

I have a file like this below,

#!/bin/bash
i=1
export basename=z-4-1_

in file "1.bash" I would like to keep as is but in file "2.bash" I would like to change in to z-4-2_ and in file "3.bash" I would like to change in to z-4-3_, and on until I get to 15.

how would like tackle this problem? by using script to modify these numbers in different files.

2 Answers 2

2

This script should do it for you:

#!/bin/bash

for i in {1..15}
do
    touch file$i.bash
    echo '#!/bin/bash' >> file$i.bash
    echo 'i=1' >> file$i.bash
    echo 'export basename=z-4-'$i'_' >> file$i.bash
done
Sign up to request clarification or add additional context in comments.

2 Comments

so this will make new files right? I was looking for just editing original files that I had.
yeah that makes new ones. if you already have them all do a rm file*.bash to delete them all first. The script will then recreate them all
0

Somewhat shorter:

for i in {1..15}
do
  echo -e "#!/bin/bash\ni=1\nexport basename=z-4-${i}_" > $i.bash
done

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.