Skip to content

Instantly share code, notes, and snippets.

@DYelamos
Created September 27, 2016 09:01
Show Gist options
  • Save DYelamos/bb664638a737d17b9d969acbed241649 to your computer and use it in GitHub Desktop.
Save DYelamos/bb664638a737d17b9d969acbed241649 to your computer and use it in GitHub Desktop.
BASH short exercise to show while, for loops, ifs and parameter parsing.
#!/bin/bash
if [ $# -eq 1 ]; then
foo=$1
while [ true ]; do
for (( i=0; i<${#foo}; i++ )); do
letter="${foo:$i:1}"
done
sleep 2
foo=$(cat /usr/share/dict/words | grep ^$letter. | sort -R | head -1)
echo $foo
done
else
echo "wrong paramethers"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment