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

1. Write a script that prints the current date, your user name, and the name of

ID: 640930 • Letter: 1

Question

1. Write a script that prints the current date, your user name, and the name of your login shell. Use variables and/or commands. Do not use literals.

2. Write a script that creates three background processes, waits for them all to complete, and then displays a simple message.

3. Experiment with the exec command by writing a series of three shell scripts called "a.sh," "b.sh," and "c.sh" that each display their name using a command line parameter, execute ps, and then exec the next script in the sequence. Observe what happens when you start the first script by: exec a.sh (Note: You are going to link your files to my working directory, so make sure your naming of and/or pathing to the files will work when they run in my directory.)

4. Write a script that echos the following special variable: $$, $0, $1, ${10}, $*, $@, and $#. The script must work with the input and output below. Your pid will be different but the rest of the rest will match.

5. Write a script that clears the screen, determines how many sessions you are in (use who, grep, and wc), compare 2 files that are passed as parameters using diff and cmp, and sort the first file.

Explanation / Answer

Hope it may helps you...

Answer for 1 is:

# function to display a line of asterices
function line(){
   echo "*************************************************"
}

echo "Your username : $(echo $USER)"
line # call function

echo "Current date and time : $(date)"
line

echo "Currently logged on users:"
who


Answer for 2 is:

#Grab the parameter off the command line delay=5
pid=$1
cmd=$2
usage=0;

if [ "$pid" == "" ] then
usage=1;
echo "PID is required"
fi

if [ "$cmd" == "" ] then
usage=1;
echo "COMMAND is required"
fi

if [ "$usage" == "1" ] then
echo "usage: waitforpid.sh PID COMMAND"
echo " where"
echo " PID = Process id to wait for"
echo " COMMAND = Command to be executed after it completes"
exit
fi