LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 07-05-2004, 03:04 AM   #1
philipina
Member
 
Registered: May 2003
Posts: 77

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


Hello,

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.

Alain.
 
Old 07-05-2004, 03:11 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
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:
Code:
#!/bin/bash

echo $#

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

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

Alain.
 
  


Reply


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 05:42 PM
C++ STL count() number of substring occurences... nyk Programming 4 06-25-2004 08:12 AM
Count number of line in a file. philipina Programming 7 03-18-2004 06:04 PM
how to find out if argument is number: bash kubicon Linux - Newbie 1 09-19-2003 05:12 PM
Count of Signals received grub Programming 3 07-17-2003 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:48 AM.

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