I have only recently gotten into coding and I need help.
I'm storing commands in an array, which are executed via SSH. I want the user to be able to enter a string of multiple lines. I then want that variable to be written to a file through SSH. I now have something along the lines of this (I have left some code out):
#!/bin/bash
content=$(cat)
commandArray=(
"echo \"$content\" >> file.txt"
)
The elements of commandArray are later executed through SSH.
The problem I have, is however with multi-line variables. Example: assume three lines of strings are entered for the variable content. If I execute the following (not throught commandArray and SSH):
echo "$content"
I get as (correct) output:
line1
line2
line3
However, when executing the commands as described above (through commandArray and SSH), the output is:
line1 line2 line3
How can I solve this problem? I need to have the same output as above. I have already tried using single quotes. Thanks in advance.