filmov
tv
become a bash pro: linear search

Показать описание
#vim #nvim #linux #terminal #tutorial #basics #terminal #bash #code #programming
code:
#!/bin/bash
#linear search
read x
arr=(1 2 4 8 16 32 64 128)
count=0
while [ $count -ne 10 ]
do
if [[ $count -gt 8 ]]
then
echo $x " was not found"
break
fi
if [[ $x = ${arr[$count]} ]]
then
echo $x " is on place " $count
break
fi
count=$(( $count + 1 ))
done
code:
#!/bin/bash
#linear search
read x
arr=(1 2 4 8 16 32 64 128)
count=0
while [ $count -ne 10 ]
do
if [[ $count -gt 8 ]]
then
echo $x " was not found"
break
fi
if [[ $x = ${arr[$count]} ]]
then
echo $x " is on place " $count
break
fi
count=$(( $count + 1 ))
done