shitou's blog 
Home About Feed | 十人族 MIX BOY 塌客

Category "linux"

09
Sep

shell中的数组 by shitou

0

shell里的数组在平时事情的情况比较少,感觉主要是操作复杂,而且没有方便的函数使用,使用起来比较晦涩,

这里简单写下吧,什么时候用到也说不定:)

 

 

#声明一个数组fruit, 也可以不用

declare -a fruit

 

#赋值,有点像ruby的方式,注意一定不能这样赋值('apple', 'banana', 'pear')

fruit=(apple banana pear)

#也可以指定索引赋值

fruit[10]='other'

#取出第一个值,和其他编程语言一样索引也是从0开始

echo ${fruit[0]}

#数组长度

echo ${#fruit[*]}

 

遍历数组

length=`expr ${#fruit[*]} - 1`

for i in `seq 0 length`

do

    echo ${fruit[i]}

done

也可以这样

for i in `echo ${#fruit[*]}`

do

    echo $i

done

 

#销毁一个数组的方法和销毁函数一样

unset fruit

 

 

感觉shell的数组没有awk中的好用,还是awk强大

Tags: shell

2008-09-09 19:49:08, 1076 reviews

send to mailbox

Your email:

Related Posts

Shell script to backup all MySQL database

【转载】命令的小总结

MySQL Innodb备份

一些shell技巧

( ),{ }的区别

一个小命令

awk同时操作两个文件

shell小技巧

Shell: 统计MySQL InnoDB表的大小

awk多维数组

0 Responses

 

TOP

Tags

tenerer MooseFS gearman-ruby Gearman MongoDB MochiChat TCP U-ka saegusa IN db command Mai Kuraki Norah Jones log iPhoneException ACG Mac Safari objective-c CouchDB LVS AJAX debian 推荐 AMQP google mail bug gettext Erlang 北京 iptables 架构 tips mysql backup function 我看 postfix 监控 SEO cache Etag memcache thread 进程 线程 无锡 yield file column mixboy xml rss gems ruby shitou shell lighttpd 安全 csrf 公司 nginx linux 模块 apache webserver 朋友 大学 生活 尼古拉斯凯奇 movie 文件同步 笑笑 歌词 auto complete plugin rails music ubuntu blog

Category

  • iPhone[17]
  • Erlang[8]
  • google[9]
  • 生活[41]
  • 音乐[11]
  • 电影[11]
  • linux[24]
  • web server[6]
  • mail server[3]
  • cluster[1]
  • system manage[8]
  • ruby[18]
  • ruby on rails[27]
  • 开源[3]

Episode

  • MochiChat
  • iPhoneException
  • shell
  • thread
  • memcache

Recent Comments

  • collectively cartoon valley, virtual http://bii...
  • mess assfilled, soderman http://gerero.centerbl...
  • croydon hoes, unlike http://zewero.centerblog.n...
  • Best Site good looking
  • Wonderfull great site
  • very best job
  • felony okcupid, bins http://biiili.centerblog.n...
  • passage mom tube, animosity http://zewero.cente...
  • this is be cool 8)
  • i'm fine good work

Popular Posts

  • 准备开始学习Erlang了(恶狼, 二郎..)
  • MySQL Innodb备份
  • Lighttpd配置参数
  • iPhone上的HelloWorld终于跑起来了
  • Etag和Expire

Recommended Posts

  • 再次被和谐-_-
  • 十人族: 上线了
  • MooseFS vs. NFS
  • Mochichat新版本上线
  • Gearman
  • MongoDB入门
  • find使用非业余研究
  • MochiChat: 一个基于erlang的web聊天室(beta)
  • /dev/shm和swap的区别
  • gen_tcp的packet参数
  • Beauty - Mai Kuraki
  • awk多维数组
  • We Lost Google.cn
  • Erlang TCP Server例子
  • Mai Kuraki -永远より ながく

Friends' blogs

  • levy
  • sphance
  • andreas

Login

   注册

留言 查看留言

留言

   取消

留言 查看留言


Statistics

  • 访问次数: 88211
  • 今天访问: 7
  • 日志: 187
  • 评论: 517
  • 音乐: 9
  • 用户: 495


 

just DO NOT support IE

close