parse arguments in bash
2016-05-18 09:37
423 查看
There are lots of ways to parse arguments in sh. Getopt is good. Here's a simple script that parses things by hand:
A sample run looks like:
转自: http://stackoverflow.com/questions/4882349/parsing-shell-script-arguments[/code]
#!/bin/sh while echo $1 | grep -q ^-; do eval $( echo $1 | sed 's/^-//' )=$2 shift shift done echo host = $host echo user = $user echo pass = $pass echo args = $@
A sample run looks like:
$ ./a.sh -host foo -user me -pass secret some args host = foo user = me pass = secret args = some args
转自: http://stackoverflow.com/questions/4882349/parsing-shell-script-arguments[/code]
相关文章推荐
- sed of shell
- awk of shell
- shell 之 test 和 [] 以及 if
- 常见linux命令释义(第八天)—— Bash Shell 的操作环境
- shell常用
- LINUX SHELL控制结构while
- linux shell编程学习--循环流程while,for,until命令
- Linux Shell for循环写法总结
- shell脚本
- shell-6.shell read 命令
- powershell小工具
- learn shell
- Shell script for logging cpu and memory usage of a Linux process
- bash 复合命令
- 转:shell杀死指定名称的进程
- 随笔1:shell递归遍历文件夹
- linux shell script脚本数组的建立和使用
- bash & && || ; & 使用方法
- 通过adb获取手机信息
- shell-printf命令详解