1

I'm trying to write a bash script that asks for input then writes it to a file.

echo "What would you like to write to that file?"
read writing
writing >> $file.txt

I tried doing something like this but it didn't work.

1 Answers1

2

You could try

echo "$writing" >> "$filename"
Tolis Gerodimos
  • 3,782
  • 2
  • 7
  • 14
  • Ah I see i was missing the $. That fixed it thanks – wesley coleman Mar 23 '22 at 09:48
  • Also, you should double-quote variable references, to avoid weird parsing in some situations: `echo "$writing" >> "$filename"`. See ["I just assigned a variable, but `echo $variable` shows something else"](https://stackoverflow.com/questions/29378566/i-just-assigned-a-variable-but-echo-variable-shows-something-else) for example. [shellcheck.net](https://www.shellcheck.net) is good at pointing out mistakes like this. – Gordon Davisson Mar 23 '22 at 17:34