📜 ⬆️ ⬇️

Do not use "!!" in bash

Every time a neophyte discovers the possibility of a bash and decides to write about it, he will tell everyone about the convenient “repeat command” method using “!!”.

Like this:
 $ touch / test
 touch: cant touch '/ test': Permission denied
 $ sudo !!
 sudo touch / test

Type, happy ending.

I have never used this, but did not think, why. I just didn’t like this idea.
')
And now I have come up with a simple counterexample that any good person will discard any desire to play with an exclamation mark in any form.

 echo NO ROOT PLEASE
  echo do it with sudo
 sudo !!

(just copy this example to shell)

The space in front of the team means "do not add me to the history." And exclamation marks obey this.

Are you always sure that you accidentally have no space at the beginning of the command line? ∎

Source: https://habr.com/ru/post/246375/


All Articles