I want to create script which use find like this:
find . -regex $1 | while read prom; do
echo $prom
done
I want to get regex from option but I can´t get this working. I tried use some regex (f. e. “.*(txt)§” ) direct instead of $1 but it didn´t help. What I forget about using find?
Is there any reason you have brackets there? Try
.*txt$as your regex (not that funny “section symbol” sign in your question).If you did want the brackets (as capturing brackets?) you have to do
.*\(txt\)$, because the default regex type forfindis Emacs-style, in which()are literal and have to be escaped to be interpreted in their regex sense.You can also do
find . -regextype posix-extended -regex '.*(txt)$', noting the-regextype posix-extendedwhich changes the regex to extended POSIX regex, where()are special characters (find -regextype asdfwill usually give you an error message listing all the options you can feed in forregextype).Also, in your bash script, you should surround the
$1in quotes :(Unless
$1is already fed in with quotes around it, in which case disregard the suggestion).