Sukhwinder Saini
Sukhwinder Saini

Reputation: 61

How to exit from the text file editing mode, when the user write EXIT?

Problem:

I want to find a proper way to exit from the text file editing, when the user write EXIT in file editing.

Script:

 #!/bin/bash
touch $1
read LINE
cat > $1
 if [[ "$LINE == "EXIT" ]]; then
 exit

fi

Upvotes: 0

Views: 616

Answers (1)

KamilCuk
KamilCuk

Reputation: 141523

Read standard input line by line, output the line and check for the desired exit string.

while IFS= read -r line; do
    printf "%s\n" "$LINE"
    if [[ $LINE == "EXIT" ]]; then
         break;
     fi
done > "$1"

Upvotes: 4

Related Questions