=== compdoc_ is now known as compdoc | ||
=== miguel is now known as Guest44856 | ||
skylite | why does sudo -u someuser bash -c "for i in {1..5}; do echo $i; done" not work the way expected? | 00:47 |
---|---|---|
jerichowasahoax | skylite: because you didn't escape the $ | 00:57 |
jerichowasahoax | skylite: so $i was expanded when the command line was processed, and since $i was empty then, you ended up with "for i in {1..5}; do echo ''; done" | 00:58 |
skylite | but it prints 5 five times | 00:58 |
jerichowasahoax | because of your for loop, yes | 00:59 |
jerichowasahoax | it set $i to 1, then ran an empty echo line, then set $i to 2, etc etc | 00:59 |
skylite | I dont really see how escaping solves this issue | 01:01 |
jerichowasahoax | it prevents $i from being expanded when processing the inital command line | 01:02 |
skylite | I tought escaping makes the shell interpret $ as a character and not as a variable sign | 01:02 |
jerichowasahoax | yes | 01:02 |
jerichowasahoax | the shell you're typing your command line into no longer interprets that as a variable to expand | 01:02 |
jerichowasahoax | so, it passes the string $i as a command line parameter | 01:03 |
skylite | I see | 01:03 |
jerichowasahoax | and THAT shell that you're running sees "$i", and goes "oh, a variable!" | 01:03 |
jerichowasahoax | remember, there's two shells here | 01:03 |
jerichowasahoax | the "bash -c" in your command line, and the shell you're running that command line in | 01:03 |
skylite | jerichowasahoax: thx | 01:06 |
jerichowasahoax | skylite: np | 01:15 |
ShriHari | hello | 05:38 |
Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!