专业的编程技术博客社区

网站首页 > 博客文章 正文

Linux Shell for in 输出数组(shell输出命令结果)

baijin 2024-08-11 13:48:45 博客文章 17 ℃ 0 评论

PHP思想:

$arr = array(1, 54, 6, 2); for.... 或者 foreach($arr as $item)..

在Shell里面定数组定义:

$arr=(1, 2, 5, 3) ;

输出为:

for item in $arr[@]

do

echo ${item}

done

在Shell中,不能直接使用 $arr这个变量,错误的写法:

for item in $arr

do

echo ${item}

done

如果使用字符串的形式定义数据:

$arr="123 456 abc"

echo $item[$index] # 就不能使用这样的索引来输出数组了

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表