请告诉我什么剂量1)-n选项2)sed' s?。* / ??'

时间:2015-09-04 14:14:21

标签: shell

if [ -n "$FULL" ]; then
    INSTALL_LIST=`cat $LIBLIST | sed 's?.*/??'`
else
    INSTALL_LIST=`ls -d *lib*/[0-9]*.[0-9][0-9] | sed 's?/.*??' | sort -u`
fi

1 个答案:

答案 0 :(得分:0)

man test

    -n STRING
           the length of STRING is nonzero

man sed

   s/regexp/replacement/
          Attempt to match regexp against the pattern space.  If successful, replace
          that portion matched with replacement.  The replacement  may  contain  the
          special  character  &  to refer to that portion of the pattern space which
          matched, and the special escapes \1 through \9 to refer to the correspond‐
          ing matching sub-expressions in the regexp.

斜杠可以替换为任何字符 - 例如问号如你的例子。所以它意味着不用任何东西替换/.*(斜杠和字符串的其余部分)。