比如有一个数组为
SH=(12 334 55 66 33 225 652)
遍历输出的话 echo ${SH[*]}
12 334 55 66 33 225 652
但我想要输出的时候以逗号分割
12,334,55,66,33,225,652
要怎么做呢?
shell 中如何格式化输出数组
- zhanju7hao
- 帖子: 32
- 注册时间: 2012-09-24 14:08
- 系统: ubuntu 12.10
- vickycq
- 帖子: 4507
- 注册时间: 2011-03-20 13:12
- 系统: Debian
- 来自: 山东省寿光县
- 联系:
Re: shell 中如何格式化输出数组
代码: 全选
$ SH=( 12 334 55 66 33 225 652 )
$ echo $(IFS=, ; echo "${SH[*]}")
12,334,55,66,33,225,652
$
http://stackoverflow.com/questions/1527 ... f-an-array
http://stackoverflow.com/questions/1347 ... ted-string
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
欢迎所有 Debian GNU/Linux 用户
- zhanju7hao
- 帖子: 32
- 注册时间: 2012-09-24 14:08
- 系统: ubuntu 12.10
Re: shell 中如何格式化输出数组
多谢!vickycq 写了:参考代码: 全选
$ SH=( 12 334 55 66 33 225 652 ) $ echo $(IFS=, ; echo "${SH[*]}") 12,334,55,66,33,225,652 $
http://stackoverflow.com/questions/1527 ... f-an-array
http://stackoverflow.com/questions/1347 ... ted-string