I set up: read -p "What will you like to name the file name? " filename
.
However if the user inputs more than a word the script will break down. How do I detect the user input to have more than one word?
Sorry! This is the code:
# provide option to rename the .ph file
while true do # user prompt for rename file and read command line argument read -p "Would you like to change the file name? (Y/N) " answer
# Handle user input
case $answer in
[Yy]* )
echo "Please enter a single word for file name. Otherwise the file name will be sequence.ph."
read -p "What will you like to name the file name? " filename
newname="$filename"
mv sequence.ph $filename.ph
echo "File has been renamed."
break
;;
[Nn]* )
newname="$1_tree"
mv sequence.ph $newname.ph
echo "Output file will have default name $1_tree.ph"
break
;;
* )
echo "Error: Invalid input."
echo "Please enter y/Y or n/N. "
;;
esac
done
$filename
and$newname
unquoted. Possible duplicate: https://unix.stackexchange.com/questions/131766 – Kusalananda Nov 07 '20 at 10:57