首页 > 用于下载的shell脚本看不懂

用于下载的shell脚本看不懂

下面这段下载文件的shell脚本中
1、 1>&2 2>&1 这些重定向
2、&cookies
3、server2.iotta.snia.org FALSE / FALSE 0 infodigest 9d0469b672fd05a798dde8385b0fcba721b276ce

4、if which wget >/dev/null 2>&1; then

都是啥含义?

#!/bin/bash
echo "Downloading trace BuildServer00" 1>&2
cookies=/tmp/cookie$$
cat > $cookies << 'EOF'
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by iotta.snia.org! Edit at your own risk.

server2.iotta.snia.org    FALSE    /    FALSE    0    infodigest    9d0469b672fd05a798dde8385b0fcba721b276ce
server2.iotta.snia.org    FALSE    /    FALSE    0    legal    true
server2.iotta.snia.org    FALSE    /    FALSE    0    id    386803
EOF

function useWGET {
  wget --load-cookies=$cookies \
    -O 'BuildServer00.zip' -c 'http://server2.iotta.snia.org/traces/159/download?type=file&sType=wget'
}
function useCURL {
  curl -b $cookies -o \
    'BuildServer00.zip' -C - -L 'http://server2.iotta.snia.org/traces/159/download?type=file&sType=curl'
}

if which wget >/dev/null 2>&1; then
  useWGET
elif which curl >/dev/null 2>&1; then
  useCURL
else
  echo "Couldn't find either wget or curl. Please install one of them" 1>&2
fi

rm -f $cookies
set -e

1.`& 是一个描述符,如果1或2前不加&,会被当成一个普通文件
1>&2 把标准输出重定向到标准错误
2>&1 把标准错误输出重定向到标准输出`
2.是$cookies吧,引用前面定义的变量,值为/tmp/cookie$$
3.<< 'EOF'这是定义一个多行字符串
4.如果存在wget命令调用useWGET函数

【热门文章】
【热门文章】