News for hackers. Stuff that matters.
Re:Advancing in the Bash Shell by executesorder66 on Tuesday September 13, 2016 @02:28AM (#12486004)
> I don't use !!

Not even "sudo !!" ?

You can see the command you just typed in the line above, and you just forgot to add sudo to it.

Re:Advancing in the Bash Shell by kbenson on Tuesday September 13, 2016 @02:37AM (#12486034)
Nope. It's easier to not have to make a decision about when to use !! or not, so I just don't. Up, Ctrl-a, "sudo ", Enter.

Another way of putting it is that I'll gladly press another 2-3 keys if it prevents a class or errors and also reduces the number of special bash instructions I have to keep in memory. !! isn't even in my repertoire, but I don't feel its loss.

Re:Advancing in the Bash Shell by stinos on Tuesday September 13, 2016 @02:42AM (#12486058)
per your own recommendations: "sudo ", alt-. would be one less keystroke
Re:Advancing in the Bash Shell by kbenson on Tuesday September 13, 2016 @04:13AM (#12486376)
yes, but it's not equivalent, as Alt-. only repeats the last argument.

For example, say you want to run "chown root:root foo". Alt-. gets you "foo", not the entire command, and "sudo foo" isn't useful,and in some cases could do something else entirely. For example, with the command "service foo restart", you would end up with "sudo restart" (which while it doesn't execute right away, is exactly what I'm guarding against).

Re:Advancing in the Bash Shell by barrkel on Tuesday September 13, 2016 @04:51AM (#12486507)
M-. takes the last argument by default, but it can grab other arguments by using numeric arguments (M-1, M-2, etc.) that usually has the effect of repeating the next command.

Unlike Emacs, M-1 etc. can't be typed as C-u 1 etc.

Re:Advancing in the Bash Shell by gmazza on Tuesday September 13, 2016 @03:43AM (#12486267)
Atl-. will cycle through the n-th argument, which is not the same as repeating entire last command with all arguments as up-arrow or !! do:

  $ yum install bash-completion
  Error: This command has to be run under the root user.
  $ sudo <Alt-.>
  $ sudo bash-completion
Re:Advancing in the Bash Shell by stinos on Tuesday September 13, 2016 @04:54AM (#12486514)
good point, so not equivalent after all
Re:Advancing in the Bash Shell by devnonymous on Tuesday September 13, 2016 @03:36AM (#12486230)
A lot of times it is also about muscle memory. For example although I also use alt+. a lot (although not as often as ctrl+alt+.), for adding sudo my brain reverts to up, ctrl+a, sudo simply because I was doing those long before I learnt about Alt+.
Re:Advancing in the Bash Shell by berntb on Tuesday September 13, 2016 @04:40AM (#12486472)
I would never get the habit of using !! with sudo. I want to read what I do, before doing root commands... (Alt-. is possible, I guess. Maybe.)

But I'm an epic coward that even looks both to the left and the right before crossing a street. :-)

Re:Advancing in the Bash Shell by p4bl0 on Tuesday September 13, 2016 @08:48AM (#12487664)
In addition to never use `sudo !!`, on systems that I use, the sudo is aliased to the following shell script:

    #!/bin/bash

    echo -n "Are you SURE you dumbass? [N/y] " >/dev/stderr
    read -n 1
    if [ "$REPLY" = "y" ]; then
      echo >/dev/stderr
      exec /usr/bin/sudo "$@"
    else
      exec echo -e "\n:-)" >/dev/stderr
    fi
That way even if I already typed my password, I systematically get asked if I'm sure I want to execute the command.
Re:Advancing in the Bash Shell by buserror on Tuesday September 13, 2016 @07:27AM (#12487075)
control-p, control-a, 'sudo ' return.

I think I'm pretty proficient as a basher, but I also never use the bang, nor do I use the 'history' bit. Didn't know about alt-. tho, that's handy.

I could toss 'control-k' for 'delete to end of line' that hasn't been mentioned. And of course control-P/N for previous/next commands (or arrows obviously).

Re:Advancing in the Bash Shell by _asummers on Tuesday September 13, 2016 @09:12AM (#12487853)
Don't forget about C-e for end of line and C-d for delete character forward. C-f and C-b make more sense to learn if you have regularly use their whole word variants Meta-f and Metals (alt f/b). Congrats, you know the emacs movement keys.