Skip to main content
7 events
when toggle format what by license comment
Jun 20, 2014 at 15:48 comment added godlygeek I don't think there's any solution that will work 100% of the time without you ever needing to modify the command. Using sudo to get a root shell and then copying and pasting the command into it would be closest, but fails if the command was expected to use variables that were set in your non-root shell. Using sudo sh -c "!!" works fine for simple commands, but is fraught for complex ones. I think that the best advice is to not expect that there is some command that will work 100% of the time - learn some possible solutions and apply each when it best fits.
Jun 20, 2014 at 15:40 comment added rubo77 So maybe there is an even better solution somehow?
Jun 20, 2014 at 15:34 comment added godlygeek Then what if your command used both single and double quotes? Or double quotes and variable expansions? If the user did: a=b and then echo "$a" >file and then sudo sh -c '!!' it would expand to sudo sh -c 'echo $a >file' which would print an empty line instead of b into file.
Jun 20, 2014 at 15:29 comment added rubo77 I tried sudo sh -c '!!' instead if your command but that doesn't work either
Jun 20, 2014 at 15:25 vote accept rubo77
Jun 20, 2014 at 22:22
Jun 20, 2014 at 15:24 comment added godlygeek If the command used quotes, this isn't necessarily equivalent. Consider echo "foo bar" which would become sh -c "echo "foo bar"" which would just print foo instead of foo bar.
Jun 20, 2014 at 15:22 history answered deltab CC BY-SA 3.0