Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 07-05-2004, 02:04 AM   #1
Registered: May 2003
Posts: 77

Rep: Reputation: 15
How to count number of argument received by a script?


I have to create a Linux script, this script will execute a loop for each argument. My question is "How to know a how many arguments is received by the script?"

rem: I work with bash.

Thank in advance.

Old 07-05-2004, 02:11 AM   #2
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
The number of arguments on the command line (not counting the script name itself) is automatically stored in the $# variable. For example:

contents of simple_script.bash:

echo $#

exit 0
[me@host]$ chmod u+x ./simple_script.bash
[me@host]$ ./simple_script.bash 1 2 3 4 5
Old 07-05-2004, 02:35 AM   #3
Registered: May 2003
Posts: 77

Original Poster
Rep: Reputation: 15
Thank a lot it works fine.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
count total number of lines in several files xushi Programming 5 11-12-2005 04:42 PM
C++ STL count() number of substring occurences... nyk Programming 4 06-25-2004 07:12 AM
Count number of line in a file. philipina Programming 7 03-18-2004 05:04 PM
how to find out if argument is number: bash kubicon Linux - Newbie 1 09-19-2003 04:12 PM
Count of Signals received grub Programming 3 07-17-2003 01:21 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration