Eytan Eytan - 5 months ago 15
Linux Question

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

I want to send little script to remote machine by ssh

the script is

#!/bin/bash
sleep 1
reboot


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

ssh 183.34.4.9 "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
#\!/bin/bash
sleep 1

Answer

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

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

# enable hostory expnsion again
set -H