#!/bin/bash args=("$@") # 将所有参数存入数组中 for i in "${!args[@]}"; do # 遍历数组 echo "参数 $i 是 ${args[$i]}" done
在命令行中运行脚本并传入参数:
$ bash index_value.sh apple banana cherry
输出结果为:
参数 0 是 apple 参数 1 是 banana 参数 2 是 cherry
上一篇:编写一个脚本,从一个网站获取实时数据,并将其显示出来。
下一篇:编写一个脚本,根据计算机是否有NVIDIA显卡来选择注册表文件