I want to ask
I have a problem, how do I get input in bash to do newlines?
read -p "List Name: " list
cat <<EOF >names.txt
List Names:
$list
EOF
i can not do a new line or use the command \n , how to add a new line command ?
I want result output names.txt like this
List Name :
Robert
James
Samuel
If you want a list with one item per line, you can use
readarray
:Now you can use
list
as normal array, e.g.${list[1]}
.By default bash uses a space character as a delimiter to separate words. This shell script uses a space character as a delimiter to separate three names that are input by the user. Paste the following shell script into a text file named input-names.sh, right click input-names.sh, select Properties -> Permissions tab and put a checkmark to the left of Allow executing file as a program.
The following output will appear after executing the above script.