I have an array of IPs and I want to pass that array as an argument to perform further operations in shell script. I want to know how to pass the array and access in shell script.
eg. ["1.2.22.22","33.2.5.2"]
you can pass the IP addresses as arguments and then make an array inside the script using $@ . this is needed to list each argument as a separate word :
arr-script.sh:
declare -a ARR
ARR=($@)
echo ${ARR[0]}
echo ${ARR[1]}
echo ${ARR[2]}
echo ${ARR[*]}
u can run it this way: sh arr-script.sh IP1 IP2 IP3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.