Skip to main content

Questions tagged [history-expansion]

The tag has no usage guidance.

7 votes
2 answers
1k views

Echoing "!" inside a string does some weird things [duplicate]

If I type in this: echo "Hello, World!" I don't know the name of it, but it prompts me for the next line. You know the PS2 thing. Or if you type echo \ and press Enter. Why? Well I know ...
0 votes
0 answers
148 views

set histchars not working in zsh

Consider the following commands for overriding the history expansion characters (which I got from Learning Shell Scripting with ZSH book): % set histchars='@^#' % ls *.txt file1.txt file2.txt % @@ ...
0 votes
0 answers
248 views

History not working in bash

When I type at the bash prompt !5 ... I simply get !5: command not found ... as the response. Any ideas about what I am doing wrong? Anything I should check?
63 votes
6 answers
47k views

How can I `alias sudo !!`?

I'm trying to set an alias for sudo !! in Bash. I tried alias sbb='sudo !!', but it interprets that as a literal !! and prints sudo: !!: command not found If I use double quotes, it substitutes ...
2 votes
1 answer
136 views

How to create alias with a caret^ command?

I have a workflow that first check git diff for specific file and then add it to stage. git diff .. ^diff^add I want to give these command a alias but this one doesn't work alias da="^diff^add&...
70 votes
2 answers
44k views

$_ vs !$. Last argument of the preceding command and output redirection

The question is about special variables. Documentation says: !!:$ designates the last argument of the preceding command. This may be shortened to !$. ($_, an underscore.) At shell startup,...
6 votes
1 answer
352 views

Bash: History expansion inside single quotes after a double quote inside the same line

I took a closer look on this phenomenon after I stumbled over it in two other questions today. I've tried all of this with the default set -H (history expansion on). To test a script, I often do ...
2 votes
1 answer
217 views

fill in from previous command arguments

Can I make the right-arrow key fill in an argument-at-a-time from the previous command line? $ mogrify -resize 50% file.jpg $ pressing right arrow now should fill in mogrify, pressing right arrow ...
1 vote
1 answer
166 views

Is there a way to match history entries on multiple words/tokens of the command, when performing history expansion?

I'm working with a command-line tool that provides a number of subcommands that all use the same binary, e.g. tool foo, tool bar, etc, and as I work, these commands are placed into my Bash shell ...
4 votes
0 answers
268 views

Zsh: Is it possible to disable history expansion inside double quotes?

Is it possible to disable history expansion inside double quotes? I do not want history expansion to be completely disabled, as I still use it, but I see no reason to expand the history inside a ...
3 votes
1 answer
136 views

How to refer to a command beginning with $?

Assume that the history list contains the command e='echo a b c' and then $e. How to refer to the command $e using the history expansion feature of bash?
5 votes
4 answers
946 views

bash - get 1st argument of current command I am editing via history, or similar? [duplicate]

Often I'm writing a command in a bash prompt, where I want to get previous arguments, in the CURRENT line I'm typing out, and put in other places in the command. A simple example, would be if I want ...
0 votes
0 answers
71 views

What does `echo ${!a}` do and why? [duplicate]

The following bash script prints out c, but I'm not sure why. a=b b=c echo ${!a} I believe that !a will be converted to the last command which began with a, so in this case that would be a=b. This ...
1 vote
2 answers
2k views

When does history expansion happen in bash?

When does history expansion happen? From bash manual Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ...
0 votes
0 answers
20 views

history expansion without execution? [duplicate]

!924 will execute that line from history. Is there a syntax where I can simply pull that line from history to the current line so I can edit it: i.e.: like using the up arrow with a built in search ...

15 30 50 per page