문자

메타문자

  • 셸 입력 문자열은 토큰(token)으로 분리된다.
  • 메타문자(metacharacter)는 셸 입력 문자열을 토큰으로 분리하는 기준이 되는 특수문자이다.
  • 메타문자에는 다음 10가지가 있다.
    1. 공백문자(space)
    2. 탭문자(tab)
    3. 개행문자(newline)
    4. |
    5. &
    6. ;
    7. (
    8. )
    9. <
    10. >

참조: syntax.h 파일

#define shell_meta_chars   "()<>;&|"
#define shell_break_chars  "()<>;&| \t\n"

토큰

  • 예약어(reserved word)
  • 연산자(operator)
  • 단어(<word>)
  • 숫자(<number>)
  • 단어 리스트(<word_list>)
  • 명령어(<command>)

참조: parse.y 파일

/* Reserved words.  Members of the first group are only recognized
   in the case that they are preceded by a list_terminator.  Members
   of the second group are for [[...]] commands.  Members of the
   third group are recognized only under special circumstances. */
%token IF THEN ELSE ELIF FI CASE ESAC FOR SELECT WHILE UNTIL DO DONE FUNCTION COPROC
%token COND_START COND_END COND_ERROR
%token IN BANG TIME TIMEOPT TIMEIGN

/* More general tokens. yylex () knows how to make these. */
%token <word> WORD ASSIGNMENT_WORD REDIR_WORD
%token <number> NUMBER
%token <word_list> ARITH_CMD ARITH_FOR_EXPRS
%token <command> COND_CMD
%token AND_AND OR_OR GREATER_GREATER LESS_LESS LESS_AND LESS_LESS_LESS
%token GREATER_AND SEMI_SEMI SEMI_AND SEMI_SEMI_AND
%token LESS_LESS_MINUS AND_GREATER AND_GREATER_GREATER LESS_GREATER
%token GREATER_BAR BAR_AND

예약어

  • if
  • then
  • elif
  • else
  • fi
  • time
  • for
  • in
  • until
  • while
  • do
  • done
  • case
  • esac
  • coproc
  • select
  • function
  • {
  • }
  • [[
  • ]]
  • !
alias bash_debug=/Users/joelkim/Work/study/study_linux/source/bash/bash
bash_debug -c "echo hello"
Starting parse
Entering state 0
Stack now 0
Reading a token
Next token is token WORD ()
Shifting token WORD ()
Entering state 13
Stack now 0 13
Reading a token
Next token is token WORD ()
Reducing stack by rule 55 (line 804):
   $1 = token WORD ()
-> $$ = nterm simple_command_element ()
Entering state 38
Stack now 0 38
Reducing stack by rule 60 (line 831):
   $1 = nterm simple_command_element ()
-> $$ = nterm simple_command ()
Entering state 39
Stack now 0 39
Next token is token WORD ()
Shifting token WORD ()
Entering state 129
Stack now 0 39 129
Reducing stack by rule 55 (line 804):
   $1 = token WORD ()
-> $$ = nterm simple_command_element ()
Entering state 130
Stack now 0 39 130
Reducing stack by rule 61 (line 833):
   $1 = nterm simple_command ()
   $2 = nterm simple_command_element ()
-> $$ = nterm simple_command ()
Entering state 39
Stack now 0 39
Reading a token
Next token is token '\n' ()
Reducing stack by rule 62 (line 837):
   $1 = nterm simple_command ()
-> $$ = nterm command ()
Entering state 40
Stack now 0 40
Reducing stack by rule 175 (line 1496):
   $1 = nterm command ()
-> $$ = nterm pipeline ()
Entering state 58
Stack now 0 58
Next token is token '\n' ()
Reducing stack by rule 168 (line 1408):
   $1 = nterm pipeline ()
-> $$ = nterm pipeline_command ()
Entering state 57
Stack now 0 57
Reducing stack by rule 167 (line 1404):
   $1 = nterm pipeline_command ()
-> $$ = nterm simple_list1 ()
Entering state 56
Stack now 0 56
Next token is token '\n' ()
Reducing stack by rule 160 (line 1340):
   $1 = nterm simple_list1 ()
-> $$ = nterm simple_list ()
Entering state 55
Stack now 0 55
Next token is token '\n' ()
Shifting token '\n' ()
Entering state 133
Stack now 0 55 133
Reducing stack by rule 151 (line 1310):
   $1 = token '\n' ()
-> $$ = nterm simple_list_terminator ()
Entering state 135
Stack now 0 55 135
Reducing stack by rule 1 (line 435):
   $1 = nterm simple_list ()
   $2 = nterm simple_list_terminator ()
Stack now 0
hello