【发布时间】:2016-03-12 13:31:20
【问题描述】:
您好,我正在制作一个带参数的 sh 脚本。 我需要用户插入 1 个参数并使用它来运行 scrapy istance。
#!/bin/sh
# sh yahooscraper.sh
if [ -z "$1"]
then
echo "ERROR you must enter one arg related to the Yahoo URL DB "
else
if ["$1" = "-h"]
then
echo "msg"
else
echo "Reading from $1 database "
cd yahooquestionscraper/yahooscraper/yahooscraper/spiders
scrapy crawl yahoo -o yahoo-url-file.json -a database_name=$1
fi
fi
此脚本在第一种情况下有效,当用户不选择任何参数时,在第二种情况下。但不要在 if ["$1" = "-h"] 条件下工作。
【问题讨论】:
-
["$1" = "-h"]=>[ "$1" = "-h" ](需要空格) -
这也是mywiki.wooledge.org/BashPitfalls中的#10
标签: macos shell if-statement command-line sh