Eytan Eytan - 3 months ago 13x
Linux Question

bash + Linux + how to ignore the character "!"

I want to send little script to remote machine by ssh

the script is

sleep 1

but I get event not found - because the "!"

ssh "echo -e '#!/bin/bash\nsleep 1\reboot>'/tmp/file"
-bash: !/bin/bash\nsleep: event not found

how to ignore the "!" char so script will so send successfully by ssh?

remark I cant use "\" before the "!" because I get

more /tmp/file
sleep 1


Use set +H before your command to disable ! style history substitution:

set +H
ssh "echo -e '#!/bin/bash\nsleep 1\reboot>'/tmp/file"

# enable hostory expnsion again
set -H