Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UNIX/LINUX QUESTION. Please solution only . Thank you! 1. Create an alias that t

ID: 3701461 • Letter: U

Question

UNIX/LINUX QUESTION. Please solution only. Thank you!

1. Create an alias that translates the command ls into ls –l. Test the alias. Give an ls command that does not use the alias. Remove the alias and show that the alias no longer exists.

2. Write a BASH script called tempConverter that takes one input argument for Fahrenheit-and processes the Fahrenheit to Celsius formula below to convert the temperature entered to

    Celsius: Celsius: C = (F – 32) * (5 / 9)

    a) First prompt the user for the city name and read the city

    b) Second prompt the user for the temperature in Fahrenheit

    c) Process the temperature conversion using the formula given above

    d) Based on the new Celsius temperature, display a short message telling the user if it’s winter, summer or fall based.

    e) Use the IF, ELSE statements to check for the season as we did in previous lab active activities.

3. Write a BASH Script/Program based on the following requirements. The program should to prompt the user for how many courses the plan to take next semester and prompt the user to enter each of those courses before displaying all the information entered back on the screen.

4. Using BASH interactive shell, instantiate an array or a list that holds three-letter abbreviations for the first six months of the year and display the list.

5. Write a BASH function named greetings that displays a simple hello message, such welcome to CSCI-50 BASH Sscrpting. Demonstrate that the function works by invoking it to show its output.

Explanation / Answer

1. Create an alias that translates the command ls into ls –l. Test the alias.

Give an ls command that does not use the alias.

Remove the alias and show that the alias no longer exists.

Ans:

alias ls='ls -l'

ls

unalias ls

2. Write a BASH script called tempConverter that takes one input argument

for Fahrenheit-and processes the Fahrenheit to Celsius formula below to convert the temperature entered to

Celsius: Celsius: C = (F – 32) * (5 / 9)

a) First prompt the user for the city name and read the city

b) Second prompt the user for the temperature in Fahrenheit

c) Process the temperature conversion using the formula given above

d) Based on the new Celsius temperature, display a short message telling the user if it’s winter, summer or fall based.

e) Use the IF, ELSE statements to check for the season as we did in previous lab active activities.

Answer:

#!/bin/bash

# summer (>28 degrees Celsius)

# winter (>23 - 28 degrees Celsius)

# fall (>17-23 degrees Celsius

# First prompt the user for the city name and read the city

echo "please provide city"

read city

# Second prompt the user for the temperature in Fahrenheit

echo "please provide temparature"

read temparature_fahrenheit

# Process the temperature conversion using the formula given above

temparature_celsius=$(echo "scale=2;(5/9)*($temparature_fahrenheit-32)"|bc)

echo "Choosen city : $city and chosen Temparature in Fahrenheit is $temparature_fahrenheit"

echo "Calculated celsius is $temparature_celsius"

# Based on the new Celsius temperature, display a short message telling the user if it’s winter, summer or fall based.

# Use the IF, ELSE statements to check for the season as we did in previous lab active activities.

if [ $( echo "$temparature_celsius > 17.0" | bc ) -eq 1 ] && [ $( echo "$temparature_celsius <= 23.0" | bc ) -eq 1 ] #winter

then

echo "For the tempaature $temparature_celsius ; The sesaon is winter"

elif [ $( echo "$temparature_celsius > 23.0" | bc ) -eq 1 ] && [ $( echo "$temparature_celsius <= 28.0" | bc ) -eq 1 ] ##fall

then

echo "For the tempaature $temparature_celsius ; The sesaon is fall "

elif [ $( echo "$temparature_celsius > 28.0" | bc ) -eq 1 ] #summer

then

echo "For the tempaature $temparature_celsius ; The sesaon is summer"

else

echo "For the tempaature $temparature_celsius ; The sesaon is undetermined"

fi

3. Write a BASH Script/Program based on the following requirements.

The program should to prompt the user for how many courses the plan to take next semester and

prompt the user to enter each of those courses before displaying all the information entered back on the screen.

Answer:

#!/bin/bash

echo "enter number of courses"

read numberOfCourses

declare -a courseList=( );

for (( i=0; i < numberOfCourses; i++ ))

do

echo "Please provide course for : $i"

read courseName

courseList="$courseList $courseName"

done

echo "Cousrses selected are: "

for outCourseName in "${courseList[@]}"

do

echo $outCourseName

done

4. Using BASH interactive shell, instantiate an array or a list that holds three-letter

abbreviations for the first six months of the year and display the list.

Answer:

#!/bin/bash

declare -a months=('Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' );

for month in "${months[@]}"

do

echo $month

done

5. Write a BASH function named greetings that displays a simple hello message,

such welcome to CSCI-50 BASH Sscrpting. Demonstrate that the function works by invoking it to show its output.

Answer:

#!/bin/bash

simpleMessage(){

echo "Welcome $1"

}

echo "enter your name"

read name

simpleMessage $name