【发布时间】:2019-02-08 03:31:16
【问题描述】:
我是编写 bash 脚本的新手,我创建了一个 npm 包 https://www.npmjs.com/package/comgen
重击
days=3
hours=24
minutes=60
totalNumberOfCommits=3
lenghtOfTime=$((days*hours*minutes))
arrayOfCommits=$(shuf -i 1-$lenghtOfTime -n $totalNumberOfCommits | sort -r -n)
for index in $arrayOfCommits
do
randomMessage=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
git commit --allow-empty --date "$(date -d "-$index minutes")" -m "$randomMessage"
done
git push origin master
你像这样运行它npm run comgen我希望它像这样运行:
npm run comgen -days "x number of days" -totalNumberOfCommits "x number of commits"
包.json
"scripts": {
"comgen": "commit-generator.sh"
},
通过的天数和提交总数将替换我在 bash 脚本中拥有的变量中的数字。
我在发布自己的帖子之前阅读了这个 SO 问题:https://unix.stackexchange.com/questions/32290/pass-command-line-arguments-to-bash-script
【问题讨论】:
标签: bash shell npm npm-scripts