Wednesday, November 4, 2020

Unix Bash Shell Script

..

my_string="A-B"
echo "Input: $my_string"
IFS='-' read -ra my_array <<< "$my_string"
len=${#my_array[@]}
for (( i=0; i<$len; i++ )); do
up=$(($i % 2))
#echo $up
if [ $up -eq 0 ]
then
echo "1. ${my_array[i]} = Cat 1"
elif [ $up -eq 1 ]
then
echo "2. ${my_array[i]} = Cat 2"
fi
done

..

$ ./cuba.sh
Input: A-B
1. A = Cat 1
2. B = Cat 2
$

No comments:

Post a Comment

Related post:

Related Posts with Thumbnails