根据 GNU 文档:
‘\<’ Match the empty string at the beginning of word.
‘\>’ Match the empty string at the end of word.
Run Code Online (Sandbox Code Playgroud)
我的 /etc/fstab 看起来像这样:
/dev/sdb1 /media/fresh ext2 defaults 0 0
Run Code Online (Sandbox Code Playgroud)
我希望 grep 为 /media/fresh 的存在返回 TRUE/FALSE。我尝试使用\<,\>但没有用。为什么?
egrep '\</media/fresh\>' /etc/fstab
Run Code Online (Sandbox Code Playgroud)
egrep '[[:blank:]]/media/fresh[[:blank:]]' /etc/fstab
Run Code Online (Sandbox Code Playgroud)
但它看起来更丑。
我的 grep 是 2.5.1
bash# hostname
host1.example.com
Run Code Online (Sandbox Code Playgroud)
我只想要host1。所以:
SHORT_HOST=$(/bin/hostname)
SHORT_HOST=${SHORT_HOST%%.*}
Run Code Online (Sandbox Code Playgroud)
我可以把它变成单衬吗?- 或者 - 使 $SHORT_HOST 只读但仍获得短主机名的最佳方法是什么?
我无法从ls使用 bash 扩展通配符的输出中仅显示一个文件。
从info bash
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 …Run Code Online (Sandbox Code Playgroud)