Modify history command on the fly
For instance:
How can recall the command in line 22 "touch myfile" so that I can modify the name myfile? 22 touch myfile 23 cp myfile ~\docs I can only run the command such as !22, but that is not what I want. Thank you rod |
Ctrl+R
start typing previous command and press the <end> key edit c-li command Press <enter> |
Code:
bind '"\e[A": history-search-backward' http://unix.stackexchange.com/questi...t-executing-it |
I don't think you understood. I need to bring the the command, and be able to modify it. The bang command executes it automatically. I just to do something like this !22 edit
the I can go and modify the command and press enter to run it. |
Why does interactive history search command (ctrl-R) not work for you - is there a reason you have to identify the command by the number and not by a matched string?
One alternative is to use the s modifier. this allows for substitution. say you have command 22 as touch myfile. you could use Code:
!22:s/myfile/yourfile Code:
touch yourfile or Code:
!22:s/touch/vim Code:
vim myfile you can also use the print modifier to just print(:p) the command so you can see what your doing. |
Quote:
Code:
shopt -s histverify has the answer by the way. Now before you might offend us further wrt: "I don't think you..." style statements, Code:
history | tail Good day, sir. |
This is what I needed:
!22:p The p modifier displays the command without executing it. The problem now is that I have to use PgUp command to access the command and be able to modify it. Thanks |
Quote:
The extra step on PageUp kind of sours the deal b/c more input is required to fully do the chore. Naturally, I favor my "muscle-memoried" bind as it removes the extra step. terminal > start typing a portion of the previous command and press Up and it fills in the rest. both bind directives and the histverify options in .bashrc could be utilized. Found this neat article: http://www.catonmat.net/blog/the-def...-line-history/ and this: http://samrowe.com/wordpress/advanci...he-bash-shell/ |
All times are GMT -5. The time now is 02:13 PM. |