Last active
January 24, 2021 13:40
-
-
Save amina-mardiyyah/3186394aa4f26b6c6b50beb7279991d3 to your computer and use it in GitHub Desktop.
Learning how to use Command Line Interface and Bash Scripting at AMMI-2021
This file contains hidden or 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
#!/bin/bash | |
#Exercise on command line interface | |
echo "****Exercise on Comand Line Interface****" | |
#Navigating to directory | |
pwd #Check current directory | |
cd /Users/diyyah;ls #new directory and list command | |
cd AMMI;ls | |
cd BashScript;ls | |
cd Week-1-Bash-Script;ls | |
cd dataset;ls | |
#Question 8 : Write a command to display Partial content of the file "population.csv" | |
less **/population.csv | |
#Question 9 : Display first line: | |
head -1 **/population.csv | |
#Question 10 : Display first 10 lines | |
head -10 **/population.csv | |
#Question 11 : Display population of comoros | |
grep 'Comoros' **/population.csv | |
#Quesiton 12 : Which country has population size of 2145194 | |
grep '2145194' **/population.csv | |
#Question 13: Replace County with Country | |
sed -i 's/County/Country/g' about.txt | |
#Exercise 2 | |
echo "******Exercise 2*****" | |
echo "******This Exercise is all about learning how to comment *****" | |
: 'This is the scripting solutions to exercises on Bash Scripting. | |
Name: Amina Rufai | |
Email Address: [email protected] | |
Date of submission: Jan 24th, 2021 | |
' | |
echo " " #Printing emptyline | |
#Exercise 1 | |
echo "******Exercise 1*****" | |
echo "******This Exercise is just defining variables to be printed in the exercise 3*****" | |
first_name=Amina #This is my first name | |
last_name=Mardiyyah #this is my last name | |
sir_name=Rufai #this is my other name | |
#Exercise 3 | |
echo "******Exercise 3*****" | |
full_name="$sir_name, $first_name $last_name" | |
#full_name='My full name is: ' #Writing a string to inform about my full name | |
echo "My full name is $full_name" | |
echo " " #Printng empty line | |
#Exercise 4 | |
#bash script_solutions.sh - to run the file | |
echo "******Exercise 4*****" | |
echo "******This Exercise is Just Executing the Script in the terminal*****" | |
#Exercise 5 | |
echo "******Exercise 5*****" | |
#Create an array Classmates | |
classmates=('Stephen' 'Mansour' 'Benjamin' 'Simon' 'Evan') | |
echo ${classmates[0]} #Printing first name of the student close to me | |
echo " " #Printing empting Line | |
echo ${classmates[*]} #Printing all the names of the students ib array-classmates | |
echo " " #Printing empting Line | |
#Exercise 6 | |
#Creating an expression -results | |
echo "******Exercise 6******" | |
results=$(((4**15+3**6-15496)/(9*12**3-56))); | |
echo $results | |
echo " " #Printing empting Line | |
#Exercise 7 | |
echo "******Exercise 7*****" | |
#Write a conditional block to check if resutls evaluated in exercise 6 is a multiple of either of 3, 4 or 5 | |
# Conditional Block | |
if [ $(( results % 4 )) -eq 0 ]; then | |
echo "$results is a multiple of 4" #Condition for checking if its a multiple of 4 | |
elif [ $(( results % 3 )) -eq 0 ]; then | |
echo "$results is a multiple of 3" #Condition for checking if its a multiple of 3 | |
elif [ $(( results % 5 )) -eq 0 ]; then | |
echo "$results is a multiple of 5" #Condition for checking if its a mutiple of 5 | |
else | |
echo "$results is neither a multiple of 4,3,or 5" | |
fi | |
#End of condition block and exercise 7 | |
echo " " #Printing empting Line | |
#Exercise 8 | |
#Write a loop to evaluate 2**20 | |
echo "******Exercise 8*****" | |
for (( i = 0; i <= 2 ; i++ )) | |
do | |
echo $((i**20)) | |
done | |
#Exercise 9 | |
echo "******Exercise 9*****" | |
function factorial() { | |
if (( $1 < 2 )) | |
then | |
echo 1 | |
else | |
echo $(( $1 * $(factorial $(( $1 - 1 ))) )) | |
fi | |
} | |
echo "The result for exercise 9" | |
factorial 4 #Testing the function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment