Skip to content

Instantly share code, notes, and snippets.

@steveoni
Last active January 24, 2021 20:57
Show Gist options
  • Save steveoni/d4dcae9d18f7c2abf90dca90e5804d30 to your computer and use it in GitHub Desktop.
Save steveoni/d4dcae9d18f7c2abf90dca90e5804d30 to your computer and use it in GitHub Desktop.
## Exercise 1
## comand to display the partial content of the file
ls **/population.csv
## display the first line of the file
head -n 1 **/population.csv
## display the first 10 lineof the file
head -n 10 **/population.csv
## write a command to get the Population of Comoros
cat **/population.csv | grep 'Comoros'
## Which countey as the population size of 2145194
cat **/population.csv | grep '2145194'
####################################
# Excercise 2 #
###################################
# About me
# stephen Oni; soni@aimsammi.org
# 24/1/2021
# Exercise 1
first_name="Stephen" # This is my first name
sur_name="Oni" # This is my sur name
last_name="Ayodele" # This is my last name
# Exercise 3
full_name="$sur_name $first_name $last_name"
echo "My full name is $full_name"
# Exercise 5
classmates=('Gbetonji', 'Lekan', 'Awa', 'Simon', 'Lawrence')
echo ${classmates[0]} # display first class mate
echo ${classmates[@]} # display all five student
# Exercise 6
numerator=$((4**15 + 3**6 - 15496))
denominator=$((9 * 12**3 - 56))
result=$((numerator / denominator ))
echo $result
# Exercise 7
if [ $((result % 4)) -eq 0 ]
then
echo "$result is a multiple of 4"
elif [ $((result % 5)) -eq 0 ]
then
echo "$result is a multiple of 5"
elif [ $((result % 3)) -eq 0 ]
then
echo "$result is a multiple of 3"
else
echo "$result is not a multiple of 4 or 3 or 5"
fi
# Exercise 9
function factorial {
factorial=1
if [ $1 -lt 0 ]
then
echo "factorial does not exist for negative number"
elif [ $1 -eq 0 ]
then
echo "factorial of 0 equal 1"
else
for i in `seq 1 $1`
do
factorial=$(( factorial * i ))
done
echo "the factorial of $1 is $factorial"
fi
}
factorial 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment