uli101_week10_practice

.docx

School

Seneca College *

*We aren’t endorsed by this school

Course

101

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

5

Uploaded by ChancellorDragonfly3067

Report
ULI101 Linux Command Practice (Shell Scripting – Part 1) _____________________________________________________________________________ Instructions: PART A: WRITE BASH SHELL SCRIPT CODE Write the answer to each question below the question in the space provided. 1. Write a Bash shell script that clears the screen and displays the text Hello World on the screen. #!/bin/bash echo “Hello World” What permissions are required to run this Bash shell script? chmod u+x pathname What are the different methods to run this Bash shell script from the command line? bash pathname 2. Write a Bash shell script that clears the screen, prompts the user for their full name and then prompts the user for their age , then clears the screen again and welcomes the user by their name and tells them their age. #!/bin/bash clear read -p “Enter your full name: “ fullname read -p “Enter your age: “ age clear echo “Welcome $fullname, your age is $age years old” What comments would you add to the above script’s contents to properly document this Bash shell script to be understood for those users that would read / edit this Bash shell script’s contents? 1 PAGE
ULI101 Linux Command Practice (Shell Scripting – Part 1) _____________________________________________________________________________ 3. Write a Bash shell script that will first set the value of a read-only variable called dogFactor to 7 . The script will then clear the screen and prompt the user to enter the age of a dog in human years (which will be stored into a variable called humanYears ). The script will store in a variable called dogYears the value of humanYears x dogFactor The script will then clear the screen a second time and then display the age of the dog in “dog years” . #!/bin/bash readonly dogFactor=7 clear read -p “Enter the age of a dog in human years: “ humanYears dogYears=$((humanYears*dofFactor)) clear echo “The age of the dog in dog years is $dogYears” 4. Write a Bash shell script that will clear the screen and then display all arguments that were entered after your Bash shell script when it was run. Also, have the Bash shell script display the number of arguments that were entered after your Bash shell script. 2 PAGE
ULI101 Linux Command Practice (Shell Scripting – Part 1) _____________________________________________________________________________ PART B: WALK-THRUS Write the expected output from running each of the following Bash shell scripts You can assume that these Bash shell script files have execute permissions. Show your work. 1. cat walkthru1.bash #!/usr/bin/bash word1=”counter” word2=”clockwise” echo “The combined word is: $word2$word1” WRITE ROUGH WORK AND OUTPUT FROM ISSUING: ./walkthru1.bash ROUGH WORK: OUTPUT: The combined word is: clockwisecounter 2. cat walkthru2.bash #!/usr/bin/bash echo “result1: $1” echo “result2: $2” echo “result3: $3” echo “result 4:” echo “$*” WRITE ROUGH WORK AND OUTPUT FROM ISSUING: ./walkthru2.bash apple orange banana ROUGH WORK: OUTPUT: result1: apple 3 PAGE
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help