I've been trying to add a user-defined file extension into a regex with no success. Here's my script:
#!/bin/bash
echo -n "Enter which file extension are you looking for: "
read fExt
find . -maxdepth 1 -type f -regextype posix-extended -regex '^./q[0-9]{1,2}[a-z]?.\"$fExt\"$'
The file names I'm looking for look like
q1.txt
q22b.pdf
q3c.JPG
This version doesn't work so I've been using multiple ext1|ext2|...
cases, which obviously isn't modular. How would I add $fExt
into my -regex
input? Is it possible in the first place, or is there an easier way to go about this? Thanks!