abs 5.参照-ワイルドカードword split Pathname Expansion

3823 ワード

[1]
ちょうど現在の作業ディレクトリの下にfirstという名前のファイルがない限り.しかし、これは引用のもう一つの原因である.(ありがとう、Harald Koenig、この点を指摘します.
テストは次のとおりです.
-bash-3.00$ bash --version
GNU bash, version 3.00.16(1)-release (i386-pc-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.
-bash-3.00$ cat test.txt 
This is first line
This is First line?

-bash-3.00$ grep '[Ff]irst' *.txt
This is first line
This is First line?
-bash-3.00$ grep [Ff]irst *.txt    
This is first line
This is First line?
-bash-3.00$ 
-bash-3.00$ touch first
-bash-3.00$ grep '[Ff]irst' *.txt
This is first line
This is First line?
-bash-3.00$ grep [Ff]irst *.txt  
This is first line

資料のまとめ:
After  word  splitting,  unless  the -f option has been set, bash scans
       each word for the characters *, ?, and [.  If one of  these  characters
       appears,  then  the word is regarded as a pattern, and replaced with an
       alphabetically sorted list of file names matching the pattern.   
If  no        matching  file  names  are found, and the shell option nullglob is dis-        abled, the word is left unchanged.
  If the nullglob option is set,  and
       no  matches  are  found,  the  word  is removed.  If the failglob shell
       option is set, and no matches are found, an error  message  is  printed
       and  the  command  is  not executed.  If the shell option nocaseglob is
       enabled, the match is performed without regard to the  case  of  alpha-
       betic  characters.   When a pattern is used for pathname expansion, the
       character ‘‘.’’  at the start of a  name  or  immediately  following  a
       slash  must  be  matched explicitly, unless the shell option dotglob is
       set.  When matching a pathname, the  slash  character  must  always  be
       matched  explicitly.   In  other  cases,  the  ‘‘.’’   character is not
       treated specially.
blackoldの文章を見てください.http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3630808&highlight=bashのコマンド処理の流れに従って、展開の前後順は:
brace expansion,
tilde expansion,
parameter、variable、arithmetic expansion 、command substitution
word splitting
pathname expansion
このうちpathname expansionはいわゆるwildcardである.
wildcardとは何か、資料のドキュメントが多くて、言うのがおっくうです.
ではwildcardはどこで起きたのでしょうか?あるいはコマンドラインのどの部分がpathname expansion(パス展開)されていますか?
bashドキュメントによると、-fオプションが設定されていない限り、すべての字にpathname expansionが行われます.
これはネットの中の人が言ったことです.
http://bbs.chinaunix.net/viewthr ... ;page=16#pid2930144
まずwildcardもcommand lineに属する処理工程でありargumentのpathに作用する.
そう、command_nameもoptionsには使わない.
wildcardの拡張と再編成の特性を理解したら、次に一般的なwildcardについて説明しましょう.
*:0または複数の文字に一致
?: 任意の単語に一致
    {string1,string2,...}: sring 1またはstring 2(またはそれ以上)の文字列を一致させる
    
出入りはありますか?
(gunguymadmanの投稿参照http://bbs.chinaunix.net/thread-1608949-1-1.html
 )
明らかに{string 1,string 2,...}wildcardではなく、brace expansionで、言わない.
実験を見る:
context:
$ echo $BASH_VERSION
3.2.48(21)-release

$ ls -1
--file=ok.txt*
--files.txt*
-file.txt*
-file=true.txt*
file
file2.txt
options:
$ echo -f*
-file.txt -file=true.txt

$ echo --file=*
--file=ok.txt

$ echo --f*
--file=ok.txt --files.txt
command:
$ set -vx

$ f* file
f* file
+ file file2.txt file
file2.txt: ASCII text
file:      ASCII text

$ set +vx
set +vx
+ set +vx
だから、このような書き方は避けるべきです.
grep -Eril --inlcude=*.c dir
またbashは,付与されたvalueと[]]でpathname expansionを実行しないとも述べているが,確かにそうである.
$ a=f*

$ echo "$a"
f*