The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-26-2000
Registered User
 

Join Date: Oct 2000
Posts: 42
In my script let's call it myfile, I want to have an option where the script changes the time format(military to standard). But to have the script change - you run the script but instead of at the command line you type: myfile,
you type myfile -r.
Now if I remember correctly I have to include:
echo $#
in my script but is that all.(# means just one argument if I remember)
Or am I missing something, also if I had a -t -w -j option would I just use:
echo $####(for 4 arguments).
Thanks.
Forum Sponsor
  #2  
Old 11-27-2000
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
$# is a shell variable which holds the number of arguments you passed to your shell script. So, if you ran:
myfile -r

Then $# would be set to 1. 'echo $#' would output '1' to the screen.



[Edited by Neo on 11-27-2000 at 11:59 PM]
  #3  
Old 11-27-2000
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,493
Quick Test Case (Example)

Create a file called 'test' with only one line in the script: echo $#

Make sure you chmod 755 test and then run:

./test

Note the results will be 0.

Then run ./test a b c

Note the results will be 3, just like PxT describes in his reply.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0