PDA

View Full Version : Unix homework !


FordFasteRR
03-18-2005, 11:49 AM
check out my week 4 homework assignment:


In each case do whatever is necessary in UNIX to be able to run a script..

1) Use vi or your favorite editor to create a shell script called my_script. The script should contain the following lines.

echo $1 $3 $2 $NEW_VAR
echo “$1” “$3” “$2” “$NEW_VAR”
echo ‘$1’ ‘$3’ ‘$2’ ‘$NEW_VAR’

Before you run the script create the variable NEW_VAR and set it to IMPRESSIVE
Run the script using command substitution to get the full path:
Then run the script again using the dot (.) command.
Use arguments as in this example:
my_script Hello there friends!

Explain the three output lines produced by the script in the two instances.


2) UNIX shell processing uses special parameters, $*, $# and $@.
Create a script called shifty2 with the following lines:

echo $*
echo $#
echo $@
shift 3
echo $*
shift 2
echo $*
shift 1
echo $*

Observe the results if you run the script using the command line:
shifty2 A B C D E F

Explain the special parameters and the shift command..




In shell programming you can create a shell variable with the statement:
let j=7
The variable j will be created and assigned the value 7.
To display the contents of the variable, you can use the statement:
echo $j


3) Create a shell script called last_one which will always display the last argument passed on the command line.
last_one A B CD EX KK V X displays X
last_one My Name is Bobby displays Bobby



.

TNT4ME
03-18-2005, 11:57 AM
Pretty damn easy if your asking...should be able to ace it no prob

hyunelan2
03-18-2005, 12:06 PM
I started reading this, then I got bored. Good luck.

FordFasteRR
03-18-2005, 12:56 PM
super easy !

:)