当前位置:网站首页>Shell uses arrays
Shell uses arrays
2022-06-21 14:50:00 【User 6978604】
Define an array
Use parentheses to define an array , The definition can be initialized with elements , It can also be defined directly :
array1=()
array2=(item1 item2 item3)Access array :
The general format is :
${arrayName[index]}for example :
echo ${array2[1]} The subscript of the array is followed by C Language is the same from 0 At the beginning , So the output above is item2
You can also access all elements , The following two methods are equivalent :
echo ${array2[*]}
echo ${array2[@]}Additional elements
array2[50]="abc"
array2[30]="def"Then let's see what the array looks like now :
#!/bin/bash
array1=()
array2=(item1 item2 item3)
array2[50]="abc"
array2[30]="def"
echo ${array2[*]}
------------------------------
[email protected]:/usr/study$ ./array.sh
item1 item2 item3 def abcYou can find , Subscripts do not need to be continuous when adding elements , When we output all the elements , If the element is null, it will be omitted automatically .
To obtain the length of the :
len=${#array2[*]}perhaps
len=${#array2[@]}You can also get the length of the array elements :
indexLen=${#array2[50]} there indexLen Refers to the number of characters of an element .
边栏推荐
- Invisible characters encountered \u200b
- Qt-5-multi window programming
- Tcp/ip FAQs
- Detailed explanation of dynamic planning
- Chapter 6 - application layer
- Native JS implements login function, and local cookies save login information -- [call Netease cloud API interface] - super detailed explanation
- New project template of punctual atom F103 based on firmware library
- Gensim error attributeerror: type object 'word2vec' has no attribute 'load_ word2vec_ format‘
- Mingw-w64 installation tutorial
- What fun things can a desk service do
猜你喜欢

Nmap scan port tool

JS written test question: array

Two of my essays

Qt-4-common classes and components

P24 de noise

Gensim error attributeerror: type object 'word2vec' has no attribute 'load_ word2vec_ format‘

Chapter 5 - application layer

DP question brushing record

Redis introduction and Practice (with source code)

Sliding validation tool class
随机推荐
JS interview questions: variable promotion function promotion, scope chain error prone questions
Flex layout --- detailed explanation [Blue Bridge Cup classic dice layout]
Clickhouse client connection
Three versions realize black-and-white theme switching
Reptile essential_ regular expression
Analysis of ROC and AUC
Alibaba cloud energy consumption treasure will be released soon to help SMEs' green upgrading and participate in the carbon neutral trillion market
Win10 install tensorflow
Qt-3-basic assembly 2
利用并查集求最小生成树
[untitled] fish pond forwarding command
Qt-7-multithreading
Pyqt5 learning notes of orange_ Basic structure of pyqt5 GUI program
English accumulation__ annoyance
Make word2vec for Bert model
How is the redemption time of financial products stipulated?
Summary of statistical learning methods
Tcp/ip FAQs
Mysql5.7 setup password and remote connection
‘maxflow‘ has no attribute ‘Graph‘