Use o "caminho" anterior em um comando [duplicado]

2

Um par de anos atrás, um ex-colega de trabalho me disse um truque no Bash que eu esqueci completamente como fazê-lo. A idéia é que quando você digita um caminho, no próximo comando você pode usar algum atalho para colocar automaticamente o caminho também.

Digamos que eu crie o diretório /tmp/test . Se então eu quero mover um arquivo lá, eu poderia mv file [shortcut that puts /tmp/test]

Qual é esse atalho?

    
por yzT 27.05.2016 / 10:18

2 respostas

0

É ESC+. ou ALT+.

mkdir mydir
cd [here you press ESC+.] mydir

Veja também: Como usar argumentos do comando anterior? | Estouro de pilha

    
por 27.05.2016 / 11:58
2

Você pode usar $_ , que é o último argumento do comando anterior:

$ mkdir /tmp/test
$ echo "$_"
  /tmp/test

Do meu /usr/share/doc/bash/bashref.html#Special-Parameters-1 :

_ ($_, an underscore.) At shell startup, set to the absolute pathname used to invoke the shell or shell script being executed as passed in the environment or argument list. Subsequently, expands to the last argument to the previous command, after expansion. Also set to the full pathname used to invoke each command executed and placed in the environment exported to that command. When checking mail, this parameter holds the name of the mail file.

Como alternativa, se você estiver no modo set -o emacs , poderá usar readline yank-last-arg (M-, M -_) .

    
por 27.05.2016 / 10:28