2022年9月10日 星期六

yum 指令,套件名稱匹配符號:「*」星號、「?」問號

yum 指令用「*」星號(匹配多個字元)、「?」問號(匹配一個字元),搭配關鍵字,匹配套件名稱時,須注意要使用「\」反斜線(Backslash)脫逸,

避免這些匹配符號,可能被 bash shell 先解釋了,導致 bash shell 傳給 yum 的指令沒有匹配符號


確保 bash shell 依預期將匹配符號傳給 yum 的方式:

  1. 使用「\」反斜線脫逸匹配符號
    # yum list php\*
    # yum list php-\?\?-\*
  2. 用雙引號或單引號,包住整個含有「*」星號的表達式
    # yum list "php*"
    # yum list 'php*'
    # yum list "php-??-*"
    # yum list 'php-??-*'



Red Hat 網站說明:
「All of yum’s list commands allow you to filter the results by appending one or more glob expressions as arguments.
 Glob expressions are normal strings of characters which contain one or more of the wildcard characters
 * (which expands to match any character subset) and
 ? (which expands to match any single character).

Be careful to escape the glob expressions when passing them as arguments to a yum command,
 otherwise the Bash shell will interpret these expressions as pathname expansions,
 and potentially pass all files in the current directory that match the global expressions to yum.
 To make sure the glob expressions are passed to yum as intended, use one of the following methods:
1.escape the wildcard characters by preceding them with a backslash character
2.double-quote or single-quote the entire glob expression.」



參考:

沒有留言:

張貼留言