Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8139224
  • 博文数量: 594
  • 博客积分: 13065
  • 博客等级: 上将
  • 技术积分: 10324
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-26 16:44
个人简介

推荐: blog.csdn.net/aquester https://github.com/eyjian https://www.cnblogs.com/aquester http://blog.chinaunix.net/uid/20682147.html

文章分类

全部博文(594)

分类: LINUX

2013-06-18 16:18:50

#!/bin/sh


foo()
{
    local basedir=$1
    local all_entries=`ls -c`


    for entry in $all_entries
    do  
        if test -d $entry; then
            cd $entry&&foo ${basedir}/$entry;cd - >/dev/null
        else
            if [[ $entry =~ .+\.(cpp|cc|h|hpp) ]]; then # 看这里
                #echo $basedir/$entry
                source_files="$source_files $basedir/$entry"
            fi  
        fi  
    done
}


foo .
echo $source_files


An additional binary operator, =~, is available, with the same precedence as == and !=.  When it is used, the string to the right of the operator is considered an extended regular expression and matched accordingly (as in  regex(3)).   The  return value  is  0 if the string matches the pattern, and 1 otherwise.  If the regular expression is syntactically incorrect, the conditional expression's return value is 2.
阅读(5333) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

aquester2013-06-19 15:25:09

aquester:emacs和posix-basic不支持()特性

find . -path ./task -prune -o -print | awk '/.cpp$|.h$/ { printf("%s ",$0); }'

语议:
if -path ./task; then
    -prune
else
    -print
fi

-o是or的意思

回复 | 举报

aquester2013-06-18 16:32:34

aquester:find . -regextype "posix-extended" -regex ".+\.(cpp|h)"

# emacs (this is the default), posix-awk, posix-basic, posix-egrep and posix-extended.

emacs和posix-basic不支持()特性

回复 | 举报

aquester2013-06-18 16:32:04

find . -regextype "posix-extended" -regex ".+\.(cpp|h)"

# emacs (this is the default), posix-awk, posix-basic, posix-egrep and posix-extended.