How can i get this feature to work?
Pressing Esc while taking inputs from the user will exit the script
read -r -p "Enter the filenames: " -a arr
if press Esc; then
read $round
mkdir $round
fi
for filenames in "${arr[@]}"; do
if [[ -e "${filenames}" ]]; then
echo "${filenames} file exists (no override)"
else
cp -n ~/Documents/library/normal.cpp "${filenames}"
fi
done
How can i detect Esc key in this script?
PS: Saw many resources
https://www.linuxquestions.org/questions/linux-newbie-8/bash-esc-key-in-a-case-statement-759927/
they use another variable like $key or read -n1 $key just one character input
but here what will i do if I've a string or an array?
Escis pressed, why not use the usualCtrl+Cto terminate the script? If there are reasons against it, please edit your post to clarify.while read Arg; do case $Arg in (*$'\e'*) echo Escape;; *) echo $Arg;; esac; done? Be aware that here the "return" key is needed to complete theread; an immediate reaction on<ESC>is not possible.