0

Below code try to save a text block to file with bash but report error:

#!/bin/sh

cat > FILE.txt <<EOF
x=1024
x=$(($x/1024))
echo $x
EOF 

Error message:

$ ./a.sh 
./a.sh: 3: ./a.sh: arithmetic expression: expecting primary: "/1024"

What's proper way to fix such error?

lucky1928
  • 8,708
  • 10
  • 43
  • 92
  • 2
    To summarize: If you want to write `$x` to the file literally because you're trying to generate a script, write `<<"EOF"` to turn off parameter expansion in the heredoc. – tjm3772 Feb 03 '23 at 19:00

0 Answers0