This repository has been archived by the owner on Dec 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add linear search using shell script.
- Loading branch information
1 parent
45f3e77
commit 01ec637
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# shell-script-linear-search | ||
*Example Linear Search in Shell script* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |