分页: 1 / 1

[问题] 直接调用通过,放到脚本里就报错的两个命令[已解决]

发表于 : 2007-03-04 23:48
5451vs5451
下面两条命令在终端下运行一点问题没有,一放到脚本里就出错。

命令一:

代码: 全选

test $PWD = @(/home/ubuntu/documents|$my_doc_base) || exit 1
错误信息:

代码: 全选

/home/ubuntu/.gnome2/nautilus-scripts/InstallDocument: line 55: syntax error near unexpected token `('
/home/ubuntu/.gnome2/nautilus-scripts/InstallDocument: line 55: `test ! $PWD = (/home/jianghua/documents|$my_doc_base) || exit 1'
命令二:

代码: 全选

temp=$(ls -d [Hh][Tt][Mm]?(L|l)/* * 2>/dev/null | 
    grep -i -m 1 '^\(.*/\)\?index\.html\?\(\.gz\)\?$') ||
temp=$(ls -d [Hh][Tt][Mm]?(L|l)/* * 2>/dev/null | 
    grep -i -m 1 '\.html\?\(\.gz\)\?$')
错误信息:

代码: 全选

/home/ubuntu/.gnome2/nautilus-scripts/InstallDocument: command substitution: line 34: syntax error near unexpected token `('
/home/ubuntu/.gnome2/nautilus-scripts/InstallDocument: command substitution: line 34: `ls -d [Hh][Tt][Mm]?(L|l)/* * 2>/dev/null | '
/home/ubuntu/.gnome2/nautilus-scripts/InstallDocument: command substitution: line 36: syntax error near unexpected token `('
/home/ubuntu/.gnome2/nautilus-scripts/InstallDocument: command substitution: line 36: `ls -d [Hh][Tt][Mm]?(L|l)/* * 2>/dev/null | '
把命令中的?(L|l)去掉后可以运行,但命令功能就变了。

发表于 : 2007-03-05 0:00
eexpress
命令输出加``包括。

发表于 : 2007-03-05 1:01
5451vs5451
原来是extglob选项没打开,先用shopt -s extglob开启,然后在运行就能通过了。

代码: 全选

If  the  extglob shell option is enabled using the shopt builtin, several extended pattern
       matching operators are recognized.  In the following description, a pattern-list is a list
       of  one  or more patterns separated by a |.  Composite patterns may be formed using one or
       more of the following sub-patterns:

              ?(pattern-list)
                     Matches zero or one occurrence of the given patterns
              *(pattern-list)
                     Matches zero or more occurrences of the given patterns
              +(pattern-list)
                     Matches one or more occurrences of the given patterns
              @(pattern-list)
                     Matches one of the given patterns
              !(pattern-list)
                     Matches anything except one of the given patterns
以前看书不仔细。 :oops: