Click to See Complete Forum and Search --> : [Bash] Can't user "!" with the echo command
hop-frog
06-19-2003, 05:02 PM
I'm trying to put this line in a new file:
<!DOCTYPE NETSCAPE-Bookmark-file-1>
I'm using this basic format:
echo "<!DOCTYPE NETSCAPE-Bookmark-file-1>" >> file_name
I've tried using a \ in front of ! but this just puts the \ in the file as well.
Bash keeps giving me errors like this:
bash: !DOCTYPE: event not found
I've read the man page, but not all of it makes sense to me.
Does anyone know how I can put that line in a file from the command line?
sploo22
06-19-2003, 05:06 PM
Try escaping the ! (with "\") and change echo to echo -e.
EDIT: Basically, the ! character is used to access bash's history feature. For example, !! means repeat the last command, !-2 the one before that, etc. You can also add various modifiers. See the bash man page under the heading "HISTORY EXPANSION".
retsaw
06-19-2003, 05:33 PM
Try using single quotes instead of double quotes, this should preserve the literal meaning, although the bash manual doesn't mention the "!" not keeping it's literal value whilst in double quotes.
hop-frog
06-19-2003, 07:50 PM
Thanks.
arn0ld
06-19-2003, 08:09 PM
from the bash man page:
Event Designators
An event designator is a reference to a command line entry in the history list.
! Start a history substitution, except when followed by a blank, newline,
echo "$DOCTYPE" ## substitute value
echo "!DOCTYPE" ## substitute command
hop-frog
06-19-2003, 08:16 PM
How did you find that? I find the bash man page most confusing to find things in. I understand it now that you showed me, but I think that even if I had scrolled down to the right spot and seen that I wouldn't have even recognized that as the answer.
arn0ld
06-19-2003, 08:31 PM
patience and serendipity. Tried
echo "<!DOCTYPENETSCAPE-Bookmark-file-1>"
got
bash: !DOCTYPE: event not found
man bash, searched for event