Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

how to reverse an array in bash scripting?

#Array declaration
array=(1 2 3 4 5 6 7) 
# Declaring index for updated reversed array
min=0
# Length of the array
max=$(( ${#array[@]} -1 ))
# Run while loop untill and unless min is less than max
while [[ min -lt max ]]
do
    # Swap current first and last elements
    x="${array[$min]}"
    array[$min]="${array[$max]}"
    array[$max]="$x"

    # Move closer
    (( min++, max-- ))
done
# Printing reverse array
echo "${array[@]}"
Comment

how to reverse an array in bash scripting?

#Array declaration
array=(1 2 3 4 5 6 7) 
# Declaring index for updated reversed array
min=0
# Length of the array
max=$(( ${#array[@]} -1 ))
# Run while loop untill and unless min is less than max
while [[ min -lt max ]]
do
    # Swap current first and last elements
    x="${array[$min]}"
    array[$min]="${array[$max]}"
    array[$max]="$x"

    # Move closer
    (( min++, max-- ))
done
# Printing reverse array
echo "${array[@]}"
Comment

PREVIOUS NEXT
Code Example
Shell :: install perl ubuntu 
Shell :: remove default firefox on ubuntu 
Shell :: git commit change message after push 
Shell :: install yarn on ec2 instance 
Shell :: ip on mac 
Shell :: apache2 does not start xampp mac 
Shell :: ubuntu install opencl 
Shell :: @react-navigation/stack install 
Shell :: install keras anaconda jupyter notebook 
Shell :: conda install scikit-learn 
Shell :: install .net sdk on ubuntu 
Shell :: ubuntu install certbot 
Shell :: unity logcat 
Shell :: install sdkman ubuntu 
Shell :: reinstall angular core 
Shell :: dd show progress 
Shell :: linux install node 
Shell :: heroku cli login 
Shell :: pip install tinymce 
Shell :: You must install graphviz to plot tree mac 
Shell :: restart webmin 
Shell :: find cudnn version 
Shell :: powershell script to disable screensaver 
Shell :: Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities, representing the time zones in which they are located 
Shell :: voice recorder for ubuntu 
Shell :: how to uninstall miniconda ubuntu 
Shell :: git remove tracked files without deleting 
Shell :: install traceroute ubuntu 18.04 
Shell :: connection failed blueman.bluez.errors.dbusfailederror protocol not available 
Shell :: how to logout of git in terminal 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =