ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Shell Patterns
    IoT 과정 2017. 7. 7. 10:08
    반응형

    Shell Patterns 과 Reg. Exp는 엄연히 다르다.

    UNIX shell의 vi 편집기능, grep, more 등에서는 Reg Exp가 사용되지만 shell에서의 file name generation, case 키워드 등에서는 Shell Patterns을 사용한다. shell의 기능이므로 man sh-posix (쉘 메뉴얼페이지, 다른 쉘을 사용한다면 다를 수 있다.) 에서 File Name Generation 메뉴를 확인할 수 있다. 메뉴얼 페이지에서 /File Name Generation/ Reg Exp를 사용해서 검색할 수 있다.


    Basic Patterns (Expressions)

    *  : Zero or more characters // leading dot string 제외, 즉 hidden file 을 피하게 생성된다.
    ?  : Exactly one character
    [abc] : Exactly one character from the group  == @(a|b|c)
    [a-z] : ASCII character from a to z

    [a-d]* : starts with a letter in the range a to d, followed by any number of additional characters
    mod??.dir : begins with mod, followed by two characters, then dot dir
    mod*0[1-9] :


    More Complex Patterns

    *(expr) : Zero or more occurrences of expr   // *(ab) = { 0, ab, abab, ababab, abababab ... }
    +(expr) : one or more occurrences of expr   // +(ab) = {ab, abab, ababab, ... }
    ?(expr) : Zero or one occurence of expr   // ?(ab) = { 0, ab }
    @(expr) : Exactly one occurence..
    !(expr) : Anything else except expr


    Pattern Combinations

    @(mod|exe)* : Beginning with mod or exe
    +(mod)* : One or more occurrences beginning with mod
    +([0-9]) : One or more digits any positive integer
    ?([0-0]) : Zero or one occurrence of a digit
    !(no) : Anything except no
    @(y|Y)* : Anything that starts with y or Y
    @(y|Y)?(e|E)?(s|S) = {y, Y, ye, yE, Ye, YE, yes, ... }, Painful way to spell yes


    Review

    @(rick|darren|steve) = { rick, darren, steve }
    *(rick|darren|steve) = { null, rick, darren, steve, rickrick, darrendarren, stevesteve, rickrickrick... }
    +(rick|darren|steve) = { rick, rickrick, ... } // same with *(pattern) except null
    !(rick|darren|steve) = anything else except pattern rick and darren, steve
    *@([0-9]) : match anystring ending with exactly one digit



    반응형

    'IoT 과정' 카테고리의 다른 글

    Array Variable  (0) 2017.07.07
    Program Loops  (0) 2017.07.07
    Shell Patterns  (0) 2017.07.07
    Branches and Logic Testing  (0) 2017.07.06
    Shell Arithmetic  (0) 2017.07.06
    Designing Program Output  (0) 2017.07.06

    댓글 0

Designed by Tistory.