Write a shell script named displayargs that prints FOUR lines. The first line tells the name that was used to invoke the script, the second line tells how many parameters there were, the third line tells what the last parameter was, and the fourth line tells what the first parameter was.
For example:

$ displayargs a b c
My name is displayargs.
There were 3 parameters.
The last one was c.
The first one was a.

You need to use $0 - $3 (and $#, etc) in your code. Try again. And then post your code. No one here is just going to give it to you.

Edited 6 Years Ago by masijade: n/a

i tried this but but the output is different from the one above?
echo "My name is $0"
echo "There were $# parameters"
echo "The last is ${!#}"
echo "The first is $1"

Did you include a "#!" line in the script (if you don't know what I mean, that means you didin't)?

If not, what is your shell?

If yes, what shell did you use (hopefully a bourne based and not a c based)?

i'm confuse now i'm using bash shell but is my code above correct or not?

i'm confuse now i'm using bash shell but is my code above correct or not?

Works for me, but it wouldn't for you if you were using a c-based shell (csh, tcsh, maybe others). That's why I asked, since you said it wasn't "working".

How does the output differ from what's expected?

this the output i got which is not the same with the above? isn't?should i change something?

my name is ./display
there were 0parameters
the last is ./dispaly args
the first is

It looks as though you executed the script without any arguments.

I.E.

./display

instead of

./display a b c
This article has been dead for over six months. Start a new discussion instead.