I am writing a bash function that takes an input as a file name and make sure it starts with an alpha character however the grep I am using to test the filename is accepting any input it is given
here is my code...
function getname(){
fname=$1;
if [ ! $1 ]; then
read -p "Enter a file name: " fname;
fi;
until ( grep -E '^[a-zA-Z_]\w+' <<< "$fname" > /dev/null 2>1&); do
if [ -d $fname ]; then
echo "Paths are not a legal file name.";
fi;
read -p "Enter a legal file name: " fname;
done
}
it will properly accept either 1 or no parameters and prompt for a file name(if no parameter) but it will accept any string that is passed to it. so how would I properly grep the string stored as fname?