unix shell 中的数组? [英] Arrays in unix shell?

查看:24
本文介绍了unix shell 中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 unix shell 脚本中创建数组?

How do I create an array in unix shell scripting?

推荐答案

以下代码在 shell 中创建并打印字符串数组:

The following code creates and prints an array of strings in shell:

#!/bin/bash
array=("A" "B" "ElementC" "ElementE")
for element in "${array[@]}"
do
    echo "$element"
done

echo
echo "Number of elements: ${#array[@]}"
echo
echo "${array[@]}"

结果:

A
B
ElementC
ElementE

Number of elements: 4

A B ElementC ElementE

这篇关于unix shell 中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆