linux shell 传递带空格的数组
2016-11-25 14:45
204 查看
本测试有两个程序,程序a接收所有的参数,并且过滤掉-skipTrash,然后调用程序b,程序b非常简单,只是把所有的参数都打印出来,证明参数是正确的。
程序a的源代码如下:
程序b的源代码如下:
测试结果:
程序a的源代码如下:
#!/bin/bash array=() for((i=1;i<=$#;i++)); do if [ "${!i}" != "-skipTrash" ]; then array[${i}]="${!i}" fi done sh b "${array[@]}"
程序b的源代码如下:
#!/bin/bash echo "in proc b" echo "Number of parameters:" $# for((i=1;i<=$#;i++)); do echo ${!i} done
测试结果:
[houzhizhen@localhost bin]$ sh a "a b" "c d" wer -skipTrash adfw a b in proc b Number of parameters: 6 a b c d wer adfw a b
相关文章推荐
- 传递带空格的参数给linux shell中的java命令
- 如何在linux Shell脚本里面把一个数组传递到awk内部进行处理
- 传递带空格的参数给linux shell中的java命令
- linux Shell脚本里面把一个数组传递到awk内部进行处理
- 如何在函数之间传递数组c++版
- bzoj 4448: [Scoi2015]情报传递 dfs序列&树状数组
- COM组件开发笔记--字符串数组的传递
- springMVC 中接收前端传递的对象、数组等数据的方式详解
- spring mvc 如何传递集合参数(list,数组)
- Linux shell 将字符串分割成数组
- 【JavaScript】jQuery+ajax传递json数组(局部响应处理)
- php中使用url传递数组
- jquery js 传递对象 数组
- jsp传递中文参数、空格以及表单内容换行问题解决小结
- 传递数组fun(int a [])和fun(int *a )的区别
- CreateInstance-数组传递
- linux shell 关联数组 hash
- 一维数组和二位数组作为函数参数进行传递的方式
- 数组的定义声明,引用传递,及拷贝操作
- [九度 1510 剑指offer]—替换空格 数组插入逆向移动