Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Commit

Permalink
Add linear search using shell script.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfquaresma authored and ayan-b committed Apr 30, 2019
1 parent 45f3e77 commit 01ec637
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions shell-script-linear-search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# shell-script-linear-search
*Example Linear Search in Shell script*
25 changes: 25 additions & 0 deletions shell-script-linear-search/shell-script-linear-search.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# number of elements. I'll not need it.
echo "Type the number of elements: "
read num_of_elements
echo "Type all elements separated by spaces (example: 1 2 3 4): "
read all_elements;
echo "Type the element you want to search: "
read element;

FOUND="NOTFOUND"
for e in $all_elements
do
if [ $element == $e ];
then
echo "Successful search!";
FOUND="FOUND";
break;
fi
done

if [ $FOUND == "NOTFOUND" ];
then
echo "Not Found!";
fi

0 comments on commit 01ec637

Please sign in to comment.