Reputation: 61
I want to find a proper way to exit from the text file editing, when the user write EXIT in file editing.
#!/bin/bash
touch $1
read LINE
cat > $1
if [[ "$LINE == "EXIT" ]]; then
exit
fi
Upvotes: 0
Views: 616
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