I'd like to write a string to a file in a bash script, but don't know how prevent variables from being expanded. An example script:
#!/bin/bash
cat >./foo.bar <<EOL
t=$(ping 8.8.8.8)
EOL
Produces the output:
t=
Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=17ms TTL=57
Reply from 8.8.8.8: bytes=32 time=16ms TTL=57
Reply from 8.8.8.8: bytes=32 time=17ms TTL=57
Reply from 8.8.8.8: bytes=32 time=17ms TTL=57
Ping statistics for 8.8.8.8:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 16ms, Maximum = 17ms, Average = 16ms
So it seems $(ping 8.8.8.8)
is being executed and the output is being written to the file. How do I write the literal string provided without expanding anything?