I wrote a function in bash which gets * as input and therefore sould list all files in that particualar dircectory. but doesn't. Here is what i wrote:
# a function that mass deletes files in a directory but asks before deleting
yrm()
{
echo "The following files are going to be deleted:"
ls "${1}"
read -e -n 1 -p "Do you want to delete these files? Y/n" ANSWER
${ANSWER:="n"} 2> /dev/null
if [ $ANSWER == "Y" ]
then
rm $1
else
echo "aborted by user"
fi
}
However I tested it with these files:
l1zard@Marvin:~/.rclocal/test$ ls *
test1.txt test2.txt test3.txt test5.txt test7.txt test8.txt test9.txt testm7m767.txt
and I get this output from my function:
l1zard@Marvin:~/.rclocal/test$ yrm *
The following files are going to be deleted:
test1.txt
Do you want to delete these files? Y/nn
aborted by user
How can I fix it so it lists the files as expected?