notes/Basic File Selection-eK2V20k7.sh
#!/bin/bash
getFile(){
clear
PS3="Please Select a File: "
options=($(find -maxdepth 1 -print0|xargs -0))
select opt in "${options[@]}" "Quit";
do
if (( REPLY == 1 + ${#options[@]}))
then
exit
elif (( REPLY > 0 && REPLY <= ${#options[@]} ))
then
opt=$(basename $opt)
echo "Your file is $opt"
break
else
echo "Not a Valid option. Please Try again."
fi
done
FILE="`pwd`/$opt"
}
if [ ! -f "$FILE" ]
then
while [ 1 ]
do
getFile
[[ -d "$FILE" ]] && cd "$FILE"
[[ -f "$FILE" ]] && break
done
fi
cat "$FILE"
syntax highlighted by Code2HTML, v. 0.9.1