Just few things which I learned.


myList="a b c d";
for my in $myListAry; do
  echo $my;

No spaces at sign of equality when assigning a value to variable. 

Instead of quotes you can use parentheses also, but in that case I was receiving some stupid error from Grunt:

Syntax error: "(" unexpected (expecting "}")

Also, in my case this example also works (without array):

myList="a b c d";
for my in $myList; do
  echo $my;

I had to do it without converting to array, because in the Grunt I was receiving error:

"Bad substitution"

Those two examples you can download from here. To test it, save it in a folder, lets say in Downloads, go to that folder:

cd Downloads

Load file:

. ./bash.sh

execute either:




To replace string in a (same) file:

sed -i.bak 's/"'$my'"/"someString"/g' /home/stanko/someFile.txt

Notice that I was using double quotes, because lets assume that in your file you want "someString" replace with my variable but to have quotes. Under single quotes dollar sign ($) is not recognized, that is why I had to "close" quotes.

Switch -i means that I want to replace string in a same file.

Also, when I was loading bash script from terminal window, it seems that variables are populated like global, just once and never again, that is why I had to close terminal window, open it again, and again to load my script, otherwise my changes inside of variables would not be visible....

To comment block, use something like this:

echo before comment
: <<'END'
bla bla
echo after comment

Copy/pasted from here.