Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
bash 将 !var_* 扩展为与通配符匹配的已定义变量($var_1 $var_2 等),例如
var_1='' var_2='' for v in ${!var_*}; do echo $v; done
返回“var_1”和“var_2”字符串
以与 /bin/sh 类似的方式迭代定义的变量的教科书方法是什么?(这样可以省去安装 bash 的麻烦。)
也许够了?
var_1='' var_2='' for v in `set | sed -n '/^var_/s/=.*//p'` do echo $v done echo ====== var_3='' for v in `set | sed -n '/^var_/s/=.*//p'` do echo $v done
将打印
var_1 var_2 ====== var_1 var_2 var_3