Results 1 to 10 of 12
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 ...
- 02-18-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 6
[SOLVED] any one can write this script please
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.
$
- 02-18-2010 #2
Hi and welcome.
Sorry, but forum rules forbid homework questions
http://www.linuxforums.org/forum/lin...ums-rules.html
But the task is not that hard.
Read here and you will surely master it
Advanced Bash-Scripting HOWTOYou must always face the curtain with a bow.
- 02-18-2010 #3Just Joined!
- Join Date
- Feb 2010
- Posts
- 6
its not an asiment its an excersice from a book i cant handle it anyway thanks
- 02-18-2010 #4
ok, so then the exercise book will give you the informations before actually asking questions about them.
One more hint, bash has special variablesYou must always face the curtain with a bow.
- 02-18-2010 #5Just Joined!
- Join Date
- Feb 2010
- Posts
- 6
i wrote it as below and i got the same output is that correct??
#!/bin/bash
clear
echo "My name is displayargs"
echo "There were 3 parameters"
echo "The last is c"
echo "The first is a"
- 02-18-2010 #6
It´s a start, but doesnt cover the scope of the task.
If you would issue
$ displayargs a b c d
Then the output should look like this
My name is displayargs.
There were 4 parameters.
The last one was d.
The first one was a.
ie: The script shall react to the number of arguments given to it, as well as its own name.
Did you read the chapter about variables?
Advanced Bash-Scripting HOWTOYou must always face the curtain with a bow.
- 02-18-2010 #7Just Joined!
- Join Date
- Feb 2010
- Posts
- 6
i did but... i'm about to give up thank u bro..
- 02-18-2010 #8
ok, I will solve the first line (only)..
try this in your script:
echo $0You must always face the curtain with a bow.
- 02-19-2010 #9Just Joined!
- Join Date
- Feb 2010
- Posts
- 6
thank u bro,i have used it this way is it ok?
echo "My name is $0"
echo "There were $# parameters"
echo "The last is ${!#}"
echo "The first is $1"
- 02-19-2010 #10Just Joined!
- Join Date
- Feb 2010
- Posts
- 6
thank u so much bro now i got it i understood how varibles works in shell scripting thanks alot again brother


