0

I am trying to write a bash script to loop over the alphabet and insert the letters as an argument in a string. This is what I've tried:

for i in {A..Z}
do
        screen -d -m bash -c 'python ~/directory/script.py  $i '  //$i is supposed to evaluate to the letter
done

I am missing how to enter the argument in the string.

kolonel
  • 1,412
  • 2
  • 16
  • 33

1 Answers1

1

Try replacing the single quotes around your 'python... line with double quotes.

Bash won't perform any expansion on strings enclosed in single quotes, which is why $i is not being parsed as you want.

Andrey Mishchenko
  • 3,986
  • 2
  • 19
  • 37
  • Yes it worked. What is the explanation for why it worked this way and no the other? – kolonel Dec 27 '13 at 04:30
  • 1
    @kolonel Because bash performs expansion on things like `$variables` within strings enclosed by double quotes, and does not perform this expansion on strings enclosed by single quotes. See http://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash. – Andrey Mishchenko Dec 27 '13 at 04:36