Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux shell array assignment method

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

In Bash, there are two ways to assign array variables:

(1) name = value1... Valuen) the subscript starts at 0 at this time

(2) name [index] = value

The following is illustrated by a simple script, which is as follows:

#! / bin/bash

# define an array

A = (a b c def)

# display the array as a string output

Echo ${A [@]}

# screen display: a b c def

# the length of the array represents ${# A [*]}

Len=$ {# A [*]}

Echo ${# A [*]}

# screen display: 4

# change the value of array elements

A [3] = 'vivian'

Echo ${A [*]}

# screen display: a b c vivian

# Loop output array elements

ITunes 0

While [$I-lt $len]

Do

Echo ${A [$I]}

Let iTunes +

Done

# screen output:

# a

# b

# c

# vivian

# another way to write the output array elements of the loop, note that in the condition, the reference variable must be in double quotes, otherwise an error will be reported

For ((jacu0; j)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report