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

Write a script called activity4.1-3 that would help practice set and shift as fo

ID: 3817491 • Letter: W

Question

Write a script called activity4.1-3 that would help practice set and shift as followed:

1.Set the positional parameters to be the output of the date

2.Display the list of positional parameter

3.Display a message in the format

•“today is , the th of ”.

•Example: Today is Tuesday, the 17th of Mar 2015

4.Set the positional parameters to be the output of the file attributes for the file this.dir

5.Define a variable access to be the first parameter

6.Shift 9 positions

7.Display the contents of $1 and the variable acccess

Include a rst line that calls the Korn shell as the interpreter

All of this is done in the korn shell. So that would be unix shell scripting.

Explanation / Answer

main.sh
--------------

#!/usr/bin/ksh

echo $1
echo $2
echo $3

echo "today is WEEKDAY, the DAYth of YEAR" | sed 's/WEEKDAY/'$1'/g' | sed 's/DAY/'$2'/g' | sed 's/YEAR/'$3'/g'

Description:

-----------------

1. To run the above script, first you need to save the content in file like main.sh

2. Provide a execute access to main.sh file using command : chmod +777 main.sh

3. Execute the main.sh with all teh postional paramters ( in our case there are three parameters)

i. e Commnad : . main.sh <WEEKDAY> <DAY> <MONTH_AND_YEAR>

. main.sh "Tuesday" "17" "Mar 2015"

4. In above script i have sed command which is resposible for searching and replaceing a partiular value of placeholder. You can see my string was : "today is WEEKDAY, the DAYth of YEAR"

now first sed command will replace WEEKDAY from first positional parameter which will pass using commnad execution i.e Thuresday

similary once weekday repealced with varaible value $1 ( first postional parameter) then repalceable string will be the input for another sed command which is used with pipeline symbol. now second sed command will repalce another string DAY withe $2( second postional parameter) and the same repelacement will happen for last and third postioanl parameter.

5. if you want to write the final output to some file then you can use ">>" operator wiht filename

i.e echo "today is WEEKDAY, the DAYth of YEAR" | sed 's/WEEKDAY/'$1'/g' | sed 's/DAY/'$2'/g' | sed 's/YEAR/'$3'/g' >> text.dir

you will get the repleacable string in testt.dir file in the same directory where this script file is placed.

Please let me know if find any problem wiht above scirpt

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