Reputation: 1
I've done a shell (bash) script that applies predefined rules to files dropped into the terminal.
It works quite well but because it uses 'read' it requires to press Enter once the files are dropped to the term window
This is part of the current code
while true ; do
echo "Drop file(s) here then press [ENTER]:"
echo "( x,q or exit,quit )"
read -p "> " read_file
while read dropped_file ;do
if [ -e ${dropped_file} ] ; then
...bunch of code here...
else
[[ "${dropped_file}" == *[xXqQ]* ]] && exit 1
fi
done <<< $(echo ${read_file} | tr " " "\n")
clear
done
I'd like to omit to press Enter each time I drop files and I was wondering if there is some wizardry to avoid to interact with the keyboard, except when I want to quit the script
Any help would be appreciated
Thanks in advance
Upvotes: 0
Views: 855
Reputation: 1979
I think you can use the yes, printf, or the expect command and use the \n
key, which should be able to perform what you are looking for.
Upvotes: -1
Reputation: 1
EDIT
I've solved with this
while true ; do
read -sn1 read_file
while read splitted_filename; do
dropped_file="${dropped_file}${splitted_filename}"
done <<< $(echo ${read_file})
functionAction
[[ "${dropped_file}" == [xXqQ] ]] && exit 1
done
Upvotes: 0