I have a command line that takes a password . The password starts with characters '!1'. E.g. '!1x9y377s' . If I execute a command with that password, then history expansion occurs and the first two letters '!1' are replaced with the 1st history entry. E.g.
ll
...list entries
echo !1x9y377s
llx9y377s
but what I wanted was:
ll
...list entries
echo !1x9y377s
!1x9y377s
Research
I soon realized that this was history expansion occurring prior to bash parsing. I searched for: How can I stop history expansion from occurring on passwords passed in the command line? Which resulted in things like this :
- superuser
- stackover
- berkley tcsh docs It states: "The `!' may be preceded by a `\' to prevent its special meaning"
I tried executing:
ll
...list entries
echo '!1x9y377s'
!1x9y377s
and
ll
...list entries
echo \!1x9y377s
!1x9y377s
both of which worked.
set +H
-- turn it back on withset -H
– glenn jackman May 14 '20 at 16:42