bash - Building the find regex parameters in shell scripts -


i'm trying build parameters used in regex expression in find command shell script seems not work.

objective of shell script able find files according specified parameters in shell script.

the shell script looks like:

#!/bin/bash ids=$1 folder="/tmp" modulenamepattern=`echo $ids | sed "s/,/|/g"` modulenamepattern=".*\\.\\($modulenamepattern\\)" echo "find command: find $folder -follow -type f -regex \"$modulenamepattern.suffix\""  filefound in `find $folder -follow -type f -regex "$modulenamepattern.suffix"`;     echo $filefound done; 

to launch it, use following command:

./test pattern1,pattern2

it generate following output:

find command: /tmp -follow -type f -regex ".*\.\(pattern1\|pattern2\).suffix"

but nothing more.

unfortunately, if execute generated find command terminal, generate following output:

/tmp/folder1/.pattern1.suffix /tmp/folder2/.pattern1.suffix /tmp/folder2/.pattern2.suffix 

i know problem. can me?

regards

you have add backslash before pipe symbol in sed-expression. quote backslash itself, need

modulenamepattern=`echo $ids | sed "s/,/\\\\\|/g"` 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -