execute script shell with regex as argument
hi all
I want to create a script shell that accept a regular expression as argument. exemple : ./my_script.sh "[a-zA-Z0-9]*\.doc" my script contains : #!/bin/bash find ./ -regextype posix-extended -regex "\./$2" -type f" but the problem is that (* and {x,y}...) in regular expression is interpreted diferently :s can you help me plz. |
Four ideas.
Firstly bash interprets \ characters in double-quoted strings so better change "[a-zA-Z0-9]*\.doc" to '[a-zA-Z0-9]*\.doc' on the command line so the script receives the string verbatim. Secondly "[a-zA-Z0-9]*\.doc" is the only command line argument passed to the script so it is $1, not $2 as used in the find command. Thirdly the same problem as the first in "\./$2". Solution to use "\\./$2" or '\./'"$2". Finally there is an unbalanced trailing double quote in find ./ -regextype posix-extended -regex "\./$2" -type f" |
any reason why you want to use regex with find?
Code:
|
All times are GMT -5. The time now is 06:14 AM. |