Skip to content

Instantly share code, notes, and snippets.

@victorjspinto
Created September 13, 2017 19:39
Show Gist options
  • Save victorjspinto/2f7c01d2e37416a8609298a7ba798d8b to your computer and use it in GitHub Desktop.
Save victorjspinto/2f7c01d2e37416a8609298a7ba798d8b to your computer and use it in GitHub Desktop.
Bash samples
#!/bin/bash
for i in {1..99..2}
do
echo "$i"
done
#!/bin/bash
# Read input name and display message
read name # ler input do usuário até o [ENTER]
echo "Welcome $name"
#!/bin/bash
# Read two integers and calculare sum, diff, mult, div
read a
read b
echo $((a + b))
echo $((a - b))
echo $((a * b))
echo $((a / b))
#!/bin/bash
# Tells if first arg is greater than second, equal, or less than
read x
read y
if [ $x -gt $y ]; then
echo "X is greater than Y"
elif [ $x -lt $y ]; then
echo "X is less than Y"
else
echo "X is equal to Y"
fi
#!/bin/bash
# Format input as YES or NO based on first char of each output
read char
if [[ $char == 'Y' ]] || [[ $char == 'y' ]]; then
echo "YES"
elif [[ $char == 'N' ]] || [[ $char == 'n' ]]; then
echo "NO"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment