I am trying to open a new terminal tab and have a for loop print the iterator.
gnome-terminal --tab -- /bin/bash -c "for (( num=1;num!=-1;num ));do echo $num; sleep 2;done"
After executing the above command for some reason it only prints out the number 3
However, if i run it the command without using gnome-terminal it works as expected.
for (( num=1;num!=-1;num ));do echo $num; sleep 2;done
Anyone know why?
CodePudding user response:
$num
will interpolate the value of num
in the original shell into the string passed as argument to the new /bin/bash
.
Use '
instead of "
to suppress interpolation.