Get the App
SLTechnology News&Howtos  ›  Servers  › 

Combing the basic knowledge of shell script & lt; + & gt;: Array

Shulou Source: shulou.com Published: 2022-06-03 04:46:14 10月03日 Update

Array definition

Static definition: array= (1 2 3)

Dynamic definition: array= ($(ls))

Array assignment: array [3] = 4

Print array

Echo ${array [0]} print array elements with ${array name [subscript]} subscript starting at 0

Echo ${array []} subscript is or @ to get the contents of the entire array

Echo ${# array [@]} get the array length

Check whether multiple website addresses are normal in batch.

Requirements: shell array method implementation, detection strategy as far as possible to simulate user access ideas

Http://www.wewe.org

Http://www.tbibib.com

Http://werrfd.com

Http://192.168.0.7

Script

#! / bin/bash

[- f / etc/init.d/functions] & &. / etc/init.d/functions

Array= (

Http://www.wewe.org

Http://www.tbibib.com

Http://werrfd.com

Http://192.168.0.7

)

Wait () {

Echo-n "wait 3s"

For ((iThin0inction iUniverse devUniverse null)

RETVAL=$?

If [$RETVAL-eq 0]; then

Action "check $1" / bin/true

Else

Action "check $1" / bin/false

Fi

Return $RETVAL

}

Main () {wait

For ((iwait)

For ((iSuppli)

Tags: Array subscript script element content dynamic address multiple ideas methods user policy site length static check detection basics basics knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker OPPO Reno Huawei Shulou Information