Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Jul 2002 13:43:24 -0700
From:      "Balaji, Pavan" <pavan.balaji@intel.com>
To:        "'Giorgos Keramidas'" <keramida@FreeBSD.org>, "Balaji, Pavan" <pavan.balaji@intel.com>
Cc:        "'freebsd-questions@freebsd.org'" <freebsd-questions@FreeBSD.org>
Subject:   RE: argc/argv in bash!
Message-ID:  <3D386AED1B47D411A94300508B11F18703BC5BA5@fmsmsx116.fm.intel.com>

next in thread | raw e-mail | index | archive | help

Thanx!

Pavan Balaji,
CIS Graduate Student,
Ohio State University

"Being happy doesn't mean that everything is perfect... It just means that
you have decided to see beyond the imperfections"  --  Rash


> -----Original Message-----
> From: Giorgos Keramidas [mailto:keramida@FreeBSD.org]
> Sent: Sunday, July 14, 2002 3:05 PM
> To: Balaji, Pavan
> Cc: 'freebsd-questions@freebsd.org'
> Subject: Re: argc/argv in bash!
> 
> 
> On 2002-07-14 12:53 +0000, Balaji, Pavan wrote:
> > 
> > How do we use argc and argv (C like) in bash scripts?
> 
> The number of command line arguments is $#.  For example:
> 
> 	% cat foo.sh
> 	#!/bin/sh
> 	echo $#
> 
> 	% sh foo.sh
> 	0
> 
> 	% sh foo.sh hello world
> 	2
> 
> 	% sh foo.sh "hello world"
> 	1
> 
> The argv[] equivalent is $@.
> 
> 	% cat foo2.sh
> 	#!/bin/sh
> 
> 	for argument in $@ ;do
> 		echo $argument
> 	done
> 
> 	% sh foo2.sh
> 	%
> 
> 	% sh foo2.sh hello world
> 	hello
> 	world
> 	%
> 
> 	% sh foo2.sh "hello world"
> 	hello world
> 	%
> 
> For more details about the "special variables" of sh, read the sh(1)
> manpage.
> 
> 	% man 1 sh
> 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D386AED1B47D411A94300508B11F18703BC5BA5>