Skip to content

bash loop if

Xu Gang edited this page Dec 14, 2021 · 10 revisions

basic

DB_AWS_ZONE=(us-east-2a us-west-1a eu-central-1a)
 
for zone in "${DB_AWS_ZONE[@]}";
do
  echo " $zone, please wait ..."
done

simple

for i in 1 2 3 4 5 10 ;
do
	echo ${i};

done

for i in {1..100}
do
 # your-unix-command-here
 echo $i
done

if

file
FILE=/etc/resolv.conf
if [ -f "$FILE" ]; then
    echo "$FILE exists."
fi

if [ -f "$FILE" ]; then
    echo "$FILE exists."
else
echo "$FILE not exists."
fi


dictory
FILE=/etc
if [ -d "$FILE" ]; then
    echo "$FILE exists."
fi

depth=0

if [ "$depth" -eq "0" ]; then
   echo "false";
   exit;
fi

#!/bin/bash

if [ "$seconds" -eq 0 ]; then
   timezone_string="Z"
elif [ "$seconds" -gt 0 ]; then
   timezone_string=$(printf "%02d:%02d" $((seconds/3600)) $(((seconds / 60) % 60)))
else
   echo "Unknown parameter"
fi
-eq # Equal
-ne # Not equal
-lt # Less than
-le # Less than or equal
-gt # Greater than
-ge # Greater than or equal
Clone this wiki locally