Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

The bit about help as a subcommand and having to edit it out in a cumbersome way really hits home.

I'm looking at you, otherwise-excellent wp-cli. :-)



view as:

You need to discover either emacs or vim shortcuts for bash. I can't imagine living without `set -o vi`

At least in bash, just run

    ^help^^
Which will rerun the previous command but substitute "help" with "" (nothing).

It is in the nature of bash that you can go a decade without ever figuring something out only to have your life changed by a random comment on the internet.

So thank you. That changes everything!


:D I have been on the receiving end enough times that I am very very happy to have passed it on this time.

Is there a shortcut to reuse the result of the last command? “which java => ll $(!!)”, but the “!!” reexecutes the last command, I’d like something which doesn’t.

I'm not personally aware of a way to do that. When I need to do that I do indeed just run $(!!)

This is amazing! I don't think I'll use it for help (up-arrow, ctrl+w is fewer keystrokes), but I can think of many other situations where I want to substitute one word of a very long command and didn't realize it could be this easy

I think

  ^help^
does the same thing. The bash manual says ^string1^string2^ is equivalent to

  !!:s/string1/string2/
where / can be any delimiter, and the "final delimiter is optional if it is the last character of the event line." So, not so surprising that the third ^ is optional too.

TIL: In either of these forms, if string1 is empty, it is set to the last string1, or, "if no previous history substitutions took place, the last string in a !?string[?] search." E.g.

  $ echo foofoo
  foofoo
  $ ^foo^
  echo foo
  foo
  $ ^^bar
  echo bar
  bar

> is equivalent to

> !!:s/string1/string2/

I didn't know about this syntax either.

I thought I knew a bit of bash and it turns out I'm a novice after all this time. How fun.


Legal | privacy