我试图获得一个生成JSDoc的bash脚本,以给出这样的给定参数
./jsdoc.sh file.js another.js maybe-a-third.js
我被困在如何将未知数量的参数传递给下一个shell命令.
(也不知道如何检查param是否存在,只有当[-z …])
#!/bin/bash # would like to know how to do positive check if [ -z "$1" ] then echo no param else d=$PWD cd ~/projects/jsdoc-toolkit/ # this bit is obvIoUsly not the right approach if [ -z "$2" ] then java -jar jsrun.jar app/run.js -a -t=templates/jsdoc/ $d/$1 else java -jar jsrun.jar app/run.js -a -t=templates/jsdoc/ $d/$1 $d/$2 fi cp -R out/jsdoc $d fi
任何其他指针,我可以如何实现这一点将不胜感激.
编辑:根据@ skjaidev的答案更新脚本 – 快乐的日子;)
#!/bin/bash d=$PWD for i in $*; do params=" $params $d/$i" done if [ -n "$1" ]; then cd ~/projects/jsdoc-toolkit/ java -jar jsrun.jar app/run.js -a -t=templates/jsdoc/ $params cp -R out/jsdoc $d fi
解决方法
$*具有所有参数.你可以迭代他们
for i in $*; do params=" $params $d/$i" done your_cmd $params