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

Question 1 (part a,b,c) bold,italics Use wget to download these two files. You w

ID: 3593626 • Letter: Q

Question

Question 1 (part a,b,c) bold,italics

Use wget to download these two files. You will use them later in the lab.

www.nku.edu/~foxr/CIT371/employees.txt

www.nku.edu/~foxr/CIT371/students.txt

Unless asked other questions, your answer to each part will be the script (2, 3, 6, 7, 9-11) or revised script (5, 8) you came up with that solves the problem. For these scripts, include the problem number in comments like #2.

Use vi to create the following script. Call the file script1. When completed, change the permissions to 745. Run the script by typing ./script1 <enter>.

#!/bin/bash

echo You are $USER

echo Your home directory is $HOME

echo Your home directory consists of `du –sH ~`

Alter your script so the output of each echo statement is redirected to the file info.txt. How did you do this?

Use vi to create the following script, calling it script2. When completed, change the permissions and run it.

#!/bin/bash

echo What is your name?

read NAME

echo What is your username?

read USERNAME

echo Hello $NAME, your home directory contents and size:

Complete this script by adding instructions to output this user’s home directory contents assuming that the user’s home directory will be /home/$USERNAME as well as using the du statement from script1 to output the disk usage of the user’s home directory.

Rewrite the script from #2 so that the NAME and USERNAME are supplied to the script by parameters and remove the first four instructions (the first two echo and the two read statements). Save and test your script.

Write the following script, calling the file script4. Change its permissions appropriately

#!/bin/bash

if [ $# -ne 2 ]; then echo Illegal input

elif [ $1 –gt $2 ]; then echo $1 is greater

else echo $2 is greater

fi

Save and run the script providing it no parameters, two parameters of 5 and 10, two parameters of 10 and 5, and two parameters of 5 and 5. What does [ $# -ne 2 ] mean? Do we need this in the script? Show how you would alter the script so that it can also output if the two parameters are the same.

Write the following script calling it script5.

#!/bin/bash

read –p “Enter the number you seek   ” NUM

for VALUE in $@; do

     if [ $VALUE –eq $NUM ]; then COUNT=$((COUNT+1)); fi

done

echo $NUM appeared $COUNT times

Run script5 passing it the list of numbers 5 10 6 12 5 18 10 4 19 21 5 12 18 22 and when prompted, input 5. Rerun the script inputting 18 instead. Rerun the script inputting 23 instead. What outputs did you get for each input?

Rewrite the script in #5 to input two inputs instead of just NUM and count the number of parameters that fall between the two. For instance, if the input is 10 and 20, we would have 5 matches (12, 18, 19, 12, 18).

Explanation / Answer

#!/bin/bash

echo You are $USER

echo Your home directory is $HOME

echo Your home directory consists of `du –sH ~`

              Then write       :qw!

Now change the permission of the file script1.sh

               After that run the file and redirect the output to the file…

=============================================================================

#!/bin/bash

echo What is your name?

read NAME

echo What is your username?

read USERNAME

echo Hello $NAME, your home directory contents and size:

What is your name?

jon

What is your username?

root

Hello jon, your home directory contents and size:

=====================================================================================

echo -n "enter the first number:"; read x
echo -n "enter the second number:"; read y
if [[ "$x" -lt "$y" ]]; then
echo "$y is greater"
elif [[ "$x" -gt "$y" ]]; then
echo "$x is greater"
else
echo "$x == $y both are equal"
fi

./script4.sh

./script2.sh 10 5

./script4.sh: line 3: [: –gt: binary operator expected

./script4.sh 5 10

./script4.sh: line 3: [: –gt: binary operator expected

./script4.sh 5 5

./script4.sh: line 3: [: –gt: binary operator expected

====================================================================================

#!/bin/bash

read –p “Enter the number you seek   ” NUM

for VALUE in $@; do

     if [ $VALUE –eq $NUM ]; then COUNT=$((COUNT+1)); fi

done

echo $NUM appeared $COUNT times

Run script5 passing it the list of numbers 5 10 6 12 5 18 10 4 19 21 5 12 18 22 and when prompted, input 5. Rerun the script inputting 18 instead. Rerun the script inputting 23 instead.

What outputs did you get for each input?

./script5.sh 5 10 6 12 5 18 10 4 19 21 5 12 18 22

5

./script5.sh: line 2: read: `–p': not a valid identifier

./script5.sh: line 4: [: 5: unary operator expected

./script5.sh: line 4: [: 10: unary operator expected

./script5.sh: line 4: [: 6: unary operator expected

./script5.sh: line 4: [: 12: unary operator expected

./script5.sh: line 4: [: 5: unary operator expected

./script5.sh: line 4: [: 18: unary operator expected

./script5.sh: line 4: [: 10: unary operator expected

./script5.sh: line 4: [: 4: unary operator expected

./script5.sh: line 4: [: 19: unary operator expected

./script5.sh: line 4: [: 21: unary operator expected

./script5.sh: line 4: [: 5: unary operator expected

./script5.sh: line 4: [: 12: unary operator expected

./script5.sh: line 4: [: 18: unary operator expected

./script5.sh: line 4: [: 22: unary operator expected

appeared times

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote