Visit Our UNIX and Linux User Community


Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers $#
# 1  
Old 11-26-2000
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).
# 2  
Old 11-27-2000
$# 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-28-2000
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:


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.

Previous Thread | Next Thread
Test Your Knowledge in Computers #273
Difficulty: Easy
In December 1939, Turing solved the essential part of the naval indicator system, which was easier and less complex than the indicator systems used by the other services.
True or False?

Featured Tech Videos