Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Shell array: Define Shell array, the array length     - Hyper-V virtual hard disk how to copy files to and attached to the virtual machine (Linux)

- Linux operating system Start Tutorial: Xmanager Remote Access Linux graphical interface (Linux)

- Linux regex sed detailing (Linux)

- Deepin Tutorial: Depth Description Installer expert mode (Linux)

- Java synchronization mechanism: synchronized, wait, notify (Programming)

- Linux iostat command example explanation (Linux)

- Build and verify MongoDB3.0.7 version (shard + replica) Cluster (Database)

- QEMU code analysis: BIOS loading process (Linux)

- To install Python-Pip and Fabric under CentOS / Ubuntu (Linux)

- Python script file directory traversal examples (Programming)

- Linux log management make the system more secure (Linux)

- CentOS set up FTP server (Server)

- Using Android Studio integrated development environment to build Android (Linux)

- CentOS 6.5 can not connect to the network under VMware (Linux)

- Using IE can also be easily remotely control the computer (Linux)

- Encounter ORA-00600: internal error code, arguments: [4194] ORA-1552 (Database)

- MongoDB study notes - polymerization (Database)

- How to convert images, audio and video formats on Ubuntu (Linux)

- REDO LOG records management (Database)

- Atheros AR8161 / AR8162 network card driver problem solving in CentOS 6.4 (Linux)

 
         
  Shell array: Define Shell array, the array length
     
  Add Date : 2018-11-21      
         
         
         
  Shell in programming a lot stronger than Windows batch, whether it is in circulation, operations.

bash supports one-dimensional array (does not support multidimensional arrays), and does not define the size of the array. Similar to the C language, the subscript of array elements from 0 start number. Gets an array of elements to take advantage of the subscript, the subscript may be an integer or arithmetic expression whose value should be greater than or equal to 0.
Define arrays

In the Shell, use parentheses to denote an array, the array elements with the "space" symbols separated. The general form of an array is defined as follows:

 array_name = (value1 ... valuen)

E.g:

array_name = (value0 value1 value2 value3)

or

array_name = (
value0
value1
value2
value3
)

You can also define separately for each component of the array:

array_name [0] = value0
array_name [1] = value1
array_name [2] = value2

You can not use a continuous index, and there is no limit under the target range.
Read array

The general format is read array element value:
    $ {Array_name [index]}
E.g:

valuen = $ {array_name [2]}

for example:

#! / Bin / sh
NAME [0] = "Zara"
NAME [1] = "Qadir"
NAME [2] = "Mahnaz"
NAME [3] = "Ayan"
NAME [4] = "Daisy"
echo "First Index: $ {NAME [0]}"
echo "Second Index: $ {NAME [1]}"

Run the script, output:

$. / Test.sh
First Index: Zara
Second Index: Qadir

Use the @ or * can get an array of all the elements, such as:

$ {Array_name [*]}
$ {Array_name [@]}

for example:

#! / Bin / sh
NAME [0] = "Zara"
NAME [1] = "Qadir"
NAME [2] = "Mahnaz"
NAME [3] = "Ayan"
NAME [4] = "Daisy"
echo "First Method: $ {NAME [*]}"
echo "Second Method: $ {NAME [@]}"

Run the script, output:

$. / Test.sh
First Method: Zara Qadir Mahnaz Ayan Daisy
Second Method: Zara Qadir Mahnaz Ayan Daisy

Get length of the array

Gets an array of lengths of string length and get the same way, for example:
Copy plaintext new window

# To obtain the number of array elements

length = $ {# array_name [@]}

Or #

length = $ {# array_name [*]}

# Obtain a single element of the array length

lengthn = $ {# array_name [n]}
     
         
         
         
  More:      
 
- Android LayoutInflater source parsing (Programming)
- About Nginx 7 (Server)
- To install Samba server on CentOS 6.6 (Server)
- The Samba service does not have permission to access (Server)
- Linux server network penetration testing (Linux)
- High-performance JavaScript loops and flow control (Programming)
- Use the Find command to help you find those files that need to be cleaned (Linux)
- ORA-04031 error appears in the solution 11.2.0.4 run utlrp.sql (Database)
- Linux environment SSH login password instead of using the RSA Certificate (Linux)
- PXE install CentOS 6.4 (Linux)
- CentOS Linux build SVN server (Server)
- Hadoop 2.6.0 standalone configuration and pseudo-distributed configuration under Ubuntu 14.04 (Server)
- Build your own Git server under Linux (Server)
- Security matters and practical Linux System (Linux)
- Ubuntu amend resolv.conf restart failure problem (Linux)
- Installation Mesos + Marathon + Zookeeper under CentOS 7 (Server)
- Compare several ways to transfer files between Linux hosts (Linux)
- Linux system on a virtual machine to access the Internet (Linux)
- CentOS 7.1 install NTFS-3G (Linux)
- Linux detection command (vmstat) (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.