扫码关注官方订阅号
Linux的参数好多都是可以通过参数名空格参数值这种方式传参的,比如
find . -name *.php
我自己写的Shell脚本,也想通过这种方式传参,怎么处理呢? 貌似Shell不提供这种方式,只能通过 $数字 的方式
认证0级讲师
可以遍历一下你获取到的参数列表$@,具体里面怎么写就看你,比如最简单的:
$@
#!/bin/bash function getName() { found=0; for item in $@ ; do if [[ $found == 1 ]]; then echo $item; found=0; break; fi if [[ "$item" == "-name" ]]; then found=1; fi done } getName $@
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
可以遍历一下你获取到的参数列表
$@,具体里面怎么写就看你,比如最简单的:#!/bin/bash function getName() { found=0; for item in $@ ; do if [[ $found == 1 ]]; then echo $item; found=0; break; fi if [[ "$item" == "-name" ]]; then found=1; fi done } getName $@