I have a shell script, where sometimes user gives the required arg sometimes they forget. So I needed someway in which if the user has already provided the particular argument then the user should not be prompted for that particular arg. Can anyone help?
Example script:
#!/bin/sh
if [ $GAME =="" ]
then
echo Enter path to GAME:
read GAME
else
echo $GAME
fi
Example O/P 1:
$ ./sd.sh -GAME asdasd
Enter path to GAME:
?asd
Example O/P 2:
$ ./sd.sh
Enter path to GAME:
asd
run.sh -name Abhishek -game COD -type Action
。如果用户有时忘记了type
,那么应该提示他/她,否则如果他已经提供了它作为参数,那么就不应该提示他/她。 - AabinGunz$3
)应该是“-game”。除非将这些参数传递给类似于 getopt 的例程,否则参数名称没有任何意义。如果您要通过参数编号进行检查,那么最好摆脱开关 - 它们在代码方面没有任何作用,并且会误导参数顺序不重要。 - cHaogetopts
命令专门用于处理命名参数。(也有一个getopt
,但它有一些怪癖--例如,它通常不能很好地处理带有空格的参数。) - cHao