创建带参数的bash脚本 [英] Creating bash scripts that take arguments
本文介绍了创建带参数的bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道该怎么问这样在bash的问题:你想创建一个目录,并根据该输入做一些事情。不过,我想创建一个bash脚本,我可以这样做:
I know how to ask questions in bash like "Would you like to create a directory" and based on that input do something. But I would like to create a bash script where I could do:
./somescriptname.sh install
./somescriptname.sh update
./somescriptname.sh assets get asset-name
./somescriptname.sh install
./somescriptname.sh update
./somescriptname.sh assets get all
我真的不知道如何阅读使用bash通过命令行参数。
I am not really sure how to read command line arguments passed in using bash.
推荐答案
使用 $ 1
, $ 2
等。访问命令行参数:
Use $1
, $2
, etc. for accessing command-line arguments:
#!/bin/sh
echo Arg 1: $1
echo Arg 2: $2
echo All args: $@
这篇关于创建带参数的bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文