linux shell is much more powerful than windows batch in programming, whether it is looping or computing. The data types are incomparable. The following is a summary of some of the operations in the array when the individual is using it.
1. Array definition
[chengmo@centos5 ~]$ a=(1 2 3 4 5)[chengmo@centos5 ~] $ echo $a1
A pair of parentheses indicates an array, and array elements are separated by a "space” symbol.
2. Array reading and assignment • get length:
[chengmo@centos5 ~]$ echo ${#a[@]}5
Use ${#array name[@ or*]} to get the array length • read:
[chengmo@centos5 ~]$ echo ${a[2]} 3
[chengmo@centos5 ~]$ echo ${a[*]} 1 2 3 4 5
With ${array name[subscript]} The subscript is starting from 0 and the subscript is: * or @Get the entire array contents • Assignment:
[chengmo@centos5 ~]$ a[1]=100
[chengmo@centos5 ~]$ echo ${a[*]} 1 100 3 4 5
[chengmo@centos5 ~]$ a[5]=100 [chengmo@centos5 ~]$ echo ${a[*]}
1 100 3 4 5 100
You can assign a reference directly to the array name [subscript]. If the subscript does not exist, automatically add a new array element • Delete:
[chengmo@centos5 ~]$ a=(1 2 3 4 5)[chengmo@centos5 ~]$ unset a[chengmo@centos5 ~]$ echo ${a[*]}
[chengmo@centos5 ~]$ a=(1 2 3 4 5)[chengmo@centos5 ~]$ unset a[1] [chengmo@centos5 ~]$ echo ${a[*]} 1 3 4 5[chengmo@centos5 ~]$ Echo ${#a[*]}4
Directly through: unset array [subscript] To clear the corresponding element, without subscripts, clears the entire data.
3.Special use •Slice:
[chengmo@centos5 ~]$ a=(1 2 3 4 5)[ ,null,null,3],Chengmo@centos5 ~]$ echo ${a[@]:0:3}1 2 3[chengmo@centos5 ~]$ echo ${a[@]:1:4}2 3 4 5
[chengmo@centos5 ~]$ c=(${a[@]:1:4})[chengmo@centos5 ~]$ echo ${#c[@]}4[chengmo@centos5 ~]$ echo ${c [*]} 2 3 4 5
Directly through ${array name[@ or*]: starting position: length} slice the original array, return a string, separated by “space” So if you add ”()”, you will get a sliced array. The above example: c is a new data. •Replace:
[chengmo@centos5 ~]$ a=(1 2 3 4 5) [chengmo@centos5 ~]$ echo ${a[@]/3/100}1 2 100 4 5 [chengmo@centos5 ~]$ echo ${a[@]}1 2 3 4 5[chengmo@centos5 ~]$ a=(${a[@]/3/100}) [chengmo@centos5 ~]$ echo ${a[@]} 1 2 100 4 5
The calling method is: ${array name[@ or*]/lookup character/replacement character} This operation does not change the original array content, if it needs to be modified You can redefine the data by looking at the above example.
From the above, you can find that the array of linux shell is very powerful, and the common operations are more than enough.
About Linux shutdown and restart commands. In fact, the first article should write about Linux inst
Kobject, kset is the basic structure of the device model. The device model uses these two structure
Regarding the circuit structure, whether it is a linear power supply, a thyristor power supply or
With Windows for a long time, it will inevitably start to lack freshness, so some people will try to
CentOS 6.2 source code compilation and installation Nginx+MySQL+PHP+WordPress installation Word
Installation and configuration of Ethernet card under Linux operating system
How to configure multiple network cards in redhat linux 6 version of bonding
Java in Chinese linux system folder appears Chinese garbled problem
Software installation and uninstallation under Linux
Add a password to the Apache directory under the Linux operating system
How to view the sector size in Linux
How to run China Merchants Bank Professional Edition under Linux
Linux server timer processing to pay attention to the problem
How to remove the alarm sound of Linux
Nginx SSL/TLS configuration for “A+” Qualys SSL Labs ratin
Linux SSH jump server reported Host key verification failed problem solved
Win7 system to open the hard disk AHCI blue screen phenomenon how to solve
IE can't download problem solution in Vista system
Win2K Terminal Service experience
Win8 system several shutdown methods explain
Microsoft: How to make Edge a browser for web developers
Win8 game can not be full screen solution = way
Flexible use of Win 2003 to build a campus network server firewall
Windows7 Beginners Tutorial: How to get started faster
How to solve the slow start of win7? Win7 boot speed slow solution