Need to get multiline input

As per my requirement, I need to get a multiline input. It can be stored in a file, that's not a problem. User will be prompted to enter steps. he should able to enter the steps in multiple lines by pressing enter.

All I know in read command that reads the input till we press enter. Can someone suggest a solution.

Thanks in advance

I clear tool, the suckiest version control I have every used, when you are checkin in or out a file and don't use the -c for comment, you can enter a multiline comment. When you enter a comment that is only a single period clear tool knows that you are done with your comment.

You can use the same character or any character you like. Just let the person running the program know what the final character should be.

With bash you can use read with the -d option something like this:

$ read -d "~" -p "Enter comment (\"~\" when done):
" line
Enter comment ("~" when done):
This is my multi line
input test
now done~$ 
$ echo "$line"
This is my multi line
input test
now done
1 Like

Can I get examples in korn shell

You could try something like

stty eof \~
echo "Enter comment type \"~\" and ENTER on blank line to end"
cat > /tmp/input.$$
stty eof ^D
line=$(cat /tmp/input.$$)
rm /tmp/input.$$
printf "You entered:\n%s\n" "$line"

Note ^D is entered in vi with CTRL-V then CTRL-D

1 Like

So would a blank line terminate the input too?

line=Dummy
until [ "$line" = "" ]
do
   read line
   # whatever processing
done

Remember that on exiting the loop, the value of line will be null. You could store the input in an array. A count of the array could then be used to process it later in your script perhaps.

What is the eventual goal?

Robin