I am newbie of shell script. Correct if I am wrong.
I have one file called ignorefileslist
in which it has file's names and patterns like /trunk/* means ignore all files from trunk.
I am able to get line of file which holds this pattern but unable to find out how to execute those pattern to get files matching that pattern. For example files inside /trunk folder for /trunk/* pattern.
ignorefileslist.txt :
/.settings
/.project
/branches/staging/test.php
/trunk/index.php
/trunk/*.php
/trunk/*
Here is my code :
if grep -q "*" "$HOME/$REPONAME/ignorablefileslist.txt";then
filewithpattern=`cat $HOME/$REPONAME/ignorablefileslist.txt | grep "*" `
echo "It contains pattern $filewithpattern"
fi
Output :
It contains pattern /trunk/*.php /trunk/*
How can I both /trunk/* and /trunk/*.php regex to get files accordingly?
如下更改grep命令,以打印包含/trunk/*
或/trunk/*.php
字符串的文件名。
grep -lP '/trunk/\*(\.php)?' *.*
如果由于某种原因需要保持条件语句完整,则可以使用循环和进程替换来避免子shell。
if grep -q "*" ignorefileslist.txt; then while read filewithpattern; do echo "It contains pattern $filewithpattern"; done < <( grep "*" ignorefileslist.txt ); fi
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.