Charlie
Charlie

Reputation: 35

Escape dash sign of bash history command

On my Ubuntu system, I would like to use bash history command to remember some commands, but when I enter command like:

history -s "-t tag_name"

bash report error:

bash: history: -t: invalid option
history: usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]

It seems the argument of -s option cannot start with dash sign, because when I enter something like

history -s "echo test"

it works fine.

How can I make history to remember a command starts with dash sign? (Without adding leading white spaces)

Upvotes: 1

Views: 488

Answers (1)

Louis Kottmann
Louis Kottmann

Reputation: 16628

You can signal history that you are done passing arguments, so it does not try to evaluate -t, like so:

history -s -- "-t tag_name"

Upvotes: 2

Related Questions