News for hackers. Stuff that matters.
Re:Unix tricks by pjungwir on Thursday March 07, 2013 @12:52PM (#5339013)
Another nice ending is `:p` to print the command instead of executing it. I use this if I'm doing something complicated and I want to make sure it's right. Or if I'm saying `!-n:foo` with n>2. Then just up-arrow and enter to run it for real.
Re:Unix tricks by cawel on Thursday March 07, 2013 @07:21PM (#5341343)
Here is a detail when using '!!:n' with ':p' when trying to iteratively construct a complex command. I want to emphasize the use of the up-arrow (which will show the interpolated arguments), as opposed to rewriting exactly what you wrote in the previous command, since the usage of ':p' will be interpreted by the shell as a command in itself:

    $ echo a b c d
    a b c d
    $ echo !!:2:p
    echo b
    $ echo !!:2
    -bash: :2: bad word specifier # there was only 1 argument in last command
However:

    $ echo a b c d
    a b c d
    $ echo !!:2:p
    echo b
    $
    <up-arrow pressed once will give the following prompt> 
    $ echo b
Re:Unix tricks by kejadlen on Thursday March 07, 2013 @12:59PM (#5339057)
I use magic-space for that in my inputrc:

  $if Bash
    Space: magic-space
  $endif
Basically does the same thing as :p, but after a space instead of enter.

Edit: fixed formatting.

Re:Unix tricks by absqua on Thursday March 07, 2013 @08:33PM (#5341626)

  shopt -s histverify
to show the expanded command before executing it. Then just enter. I never get these right the first time.
Re:Unix tricks by pyre on Thursday March 07, 2013 @10:46PM (#5341978)
In zsh, you can hit <tab> to expand it in place before hitting <enter>.