i'm new to shell can handle this script for me plz


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting i'm new to shell can handle this script for me plz
# 1  
Old 02-17-2010
i'm new to shell can handle this script for me plz

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:
Code:
  $ display args  a b c
  My name is  displayargs.
  There were 3  parameters.
  The last one  was c.
  The first one  was a.


Last edited by zxmaus; 02-18-2010 at 04:35 AM.. Reason: code tags added
# 2  
Old 02-17-2010
quick fix
Code:
first="$1"
let n=$#-1
shift $n
last="$1"

echo "
My name is $0
There were $# parameters
The last one was $last
The first one was $first
"

# 3  
Old 02-18-2010
simpler :
Code:
echo "My name is $0"
echo "There were $# parameters"
echo "The last is ${!#}"
echo "The first is $1"

# 4  
Old 02-19-2010
thank u but thats it?
# 5  
Old 02-19-2010
What do you mean "that's it"? Of course that's it, you don't need any more code to display some command line arguments.
# 6  
Old 02-19-2010
i'm confuse bcoz i got this output which is not the same output in the question

my name is ./displayargs
there were 0 parameteres
the last is ./displayargs
the first is
# 7  
Old 02-19-2010
that's because you did not give any argument.
I'm sur you are able to modify the script so that it take care of that possibility. The syntax :
Code:
if ...
then ...
else ...
fi ...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is there a way to handle commas inside the data when generating a csv file from shell script?

I am extracting data via sql query and some of the data has commas. Output File must be csv and I cannot update the data in the db (as it is used by other application). Example table FavoriteThings Person VARCHAR2(25), Favorite VARCHAR2(100) Sample Data Greta rain drop on... (12 Replies)
Discussion started by: patk625
12 Replies

2. Shell Programming and Scripting

error in shell script while returning values-- urgent issue plz help.

Hi, I have initailized a varaible EBID as typeset Long EBID=0 i am calculating value of EBID using certian formula as below: (( CURR_EBID= ($BANDINDEX << 27) | ($CURR_FREQ << 16) | ($CURR_CELLID << 4) | $CURR_SECTOR_VALUE )) return $CURR_EBID The output is as below: + (( CURR_EBID=... (6 Replies)
Discussion started by: kasanur
6 Replies

3. Shell Programming and Scripting

plz help normal doubt abt shell script

How to print a only files and not directories in a path. for exam :a user consists both files and directoris in his path. i have to write a script to display only files not dirctories. and only dirctories not files. Advance thanks to forum members.:) (5 Replies)
Discussion started by: sivaranga001
5 Replies

4. Shell Programming and Scripting

How to handle case insensitive in shell scripting

Hi All, I am new to this forum also new to shell scripting. I have a requirement to read a text from a file which can be in any case like LOGFILE or LogFile or logfile or lOgfILE etc.. Can you guys help me out. Thanks, Bacsi01 (1 Reply)
Discussion started by: bacsi01
1 Replies

5. Shell Programming and Scripting

Shell Script to Handle Quarterly Backup.

Hi I'm not to shell script and I'm trying to write a simple shell code to do the following. Shell script should be run in March, June, Sept, & Dec respectively to back up files last modified in the 1st, 2nd, 3rd, and 4th quarters. I've have the following code. #!/bin/csh set v1 = `date... (1 Reply)
Discussion started by: Magshabib@gmail
1 Replies

6. UNIX for Dummies Questions & Answers

Shell Script Help Plz

####################################################################### # #This script will perform the menu such as : list file, change catalog, #file check, # #This script was written in UNIX Shell Programming Language #... (3 Replies)
Discussion started by: shekhani
3 Replies

7. Shell Programming and Scripting

Plz correct my syntax of shell script

Dear all I am still bit new in shell script area.I am writing down a shell script which I guess somewhere wrong so please kindly correct it. I would be greatful for that. What I actually want from this shell script is that it will move all the files one by one to another server which can be... (2 Replies)
Discussion started by: girish.batra
2 Replies

8. Shell Programming and Scripting

shell script to call other files..plz help

Hi all, I have a number of shell script,perl script.. etc in a directory,which i need to execute in some order.Now i need to create a script to call all these files in that order..so that the new script will execute all the files one by one....plz help this is urgent. Thanks In advance Anju (3 Replies)
Discussion started by: anju
3 Replies

9. Shell Programming and Scripting

plz help me by creating required shell script

Dear all I am new to shell script. And this is my first post to this site as well as this forum. I would like to tell this forum that I require shell script, which is regarding transfers of files from a specific directory in a server A to server B on a specific directory through sftp command.... (5 Replies)
Discussion started by: girish.batra
5 Replies

10. Shell Programming and Scripting

Shell script to find out 2 last modified files in a folder..PLZ HELP!!!!!!!!!

hi all, I need to find out the last 2 modified files in a folder.There is some way by which,we can check the timestamp and find out..??please help this is urgent. Thanks in Advance Anju (3 Replies)
Discussion started by: anju
3 Replies
Login or Register to Ask a Question