我是linux bash的新手,这是一个令我困惑的问题。我不明白" hash wget"。它的目的是什么,为什么应该进行if检查?
if [ ! -e text8 ]; then
if **hash wget 2>/dev/null**; then
wget http://mattmahoney.net/dc/text8.zip
else
curl -O http://mattmahoney.net/dc/text8.zip
fi
unzip text8.zip
rm text8.zip
fi
答案 0 :(得分:0)
如果wget
可用(在PATH
中),则hash wget
的退出代码为0,因此语句将执行。重定向2>/dev/null
只是在找不到wget
时重定向错误消息。使用bash提示符中的help hash
来阅读其信息。
答案 1 :(得分:0)
在命令行中键入help hash。
XXXXX @ ubuntu:〜$ help hash hash:hash [-lr] [-p路径名] [-dt] [名称...] 记住或显示程序位置。
Determine and remember the full pathname of each command NAME. If
no arguments are given, information about remembered commands is displayed.
Options:
-d forget the remembered location of each NAME
-l display in a format that may be reused as input
-p pathname use PATHNAME as the full pathname of NAME
-r forget all remembered locations
-t print the remembered location of each NAME, preceding
each location with the corresponding NAME if multiple
NAMEs are given
Arguments:
NAME Each NAME is searched for in $PATH and added to the list
of remembered commands.
Exit Status:
Returns success unless NAME is not found or an invalid option is given.