Hi all , its been a while since I wrote a bash script but I've run into some trouble in the while clause. The answer reads in fine but it doesn't register that a valid answer has been entered and just assumes that every answer entered is invalid.
I think it has to do with how Im doing on the comparisons , if anyone could provide any insight as to why this is not working I would appreciate it.
Code:
#!/bin/bash
# script to list all the files in the downloads directory and ask the user
# if they wish to move the files and if so , into which directory
# Eg Music Videos Pictures Distros etc
EX_HDD="/media/Expansion\ Drive/"
for f in $(ls "$HOME/Downloads/")
do
echo "Would you like to move $f to External HDD? Y/N"
read answer
while [ '$answer' != 'Y' ] || [ '$answer' != 'N' ] # Problem line
do
echo "Answer must be of the form Y or N"
echo "Would you like to move $f to External HDD? Y/N"
echo "Answer is $answer"
read answer
done
echo "working so far"
done
Sample output:
Would you like to move 119305-GlassMaxX.tar.gz to External HDD? Y/N
Y
Answer must be of the form Y or N
Would you like to move 119305-GlassMaxX.tar.gz to External HDD? Y/N
Answer is Y
N
Answer must be of the form Y or N
Would you like to move 119305-GlassMaxX.tar.gz to External HDD? Y/N
Answer is N
Y
Answer must be of the form Y or N
Would you like to move 119305-GlassMaxX.tar.gz to External HDD? Y/N
Answer is Y
HJHJ
Answer must be of the form Y or N
Would you like to move 119305-GlassMaxX.tar.gz to External HDD? Y/N
Answer is HJHJ