/srv/irclogs.ubuntu.com/2018/03/31/#ubuntu-server.txt

=== compdoc_ is now known as compdoc
=== miguel is now known as Guest44856
skylitewhy does sudo -u someuser bash -c "for i in {1..5}; do echo $i; done" not work the way expected?00:47
jerichowasahoaxskylite: because you didn't escape the $00:57
jerichowasahoaxskylite: 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
skylitebut it prints 5 five times00:58
jerichowasahoaxbecause of your for loop, yes00:59
jerichowasahoaxit set $i to 1, then ran an empty echo line, then set $i to 2, etc etc00:59
skyliteI dont really see how escaping solves this issue01:01
jerichowasahoaxit prevents $i from being expanded when processing the inital command line01:02
skyliteI tought escaping makes the shell interpret $ as a character and not as a variable sign01:02
jerichowasahoaxyes01:02
jerichowasahoaxthe shell you're typing your command line into no longer interprets that as a variable to expand01:02
jerichowasahoaxso, it passes the string $i as a command line parameter01:03
skyliteI see01:03
jerichowasahoaxand THAT shell that you're running sees "$i", and goes "oh, a variable!"01:03
jerichowasahoaxremember, there's two shells here01:03
jerichowasahoaxthe "bash -c" in your command line, and the shell you're running that command line in01:03
skylitejerichowasahoax: thx01:06
jerichowasahoaxskylite: np01:15
ShriHarihello05:38

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!