From owner-freebsd-questions Sun Jul 14 13: 7:19 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CD52337B400 for ; Sun, 14 Jul 2002 13:07:16 -0700 (PDT) Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id AA70643E6D for ; Sun, 14 Jul 2002 13:07:15 -0700 (PDT) (envelope-from keramida@FreeBSD.org) Received: from hades.hell.gr (patr530-a119.otenet.gr [212.205.215.119]) by mailsrv.otenet.gr (8.12.4/8.12.4) with ESMTP id g6EK7BPY019299; Sun, 14 Jul 2002 23:07:12 +0300 (EEST) Received: from hades.hell.gr (hades [127.0.0.1]) by hades.hell.gr (8.12.5/8.12.5) with ESMTP id g6EK5pft039440; Sun, 14 Jul 2002 23:05:51 +0300 (EEST) (envelope-from keramida@FreeBSD.org) Received: (from charon@localhost) by hades.hell.gr (8.12.5/8.12.5/Submit) id g6EK5pcR039407; Sun, 14 Jul 2002 23:05:51 +0300 (EEST) (envelope-from keramida@FreeBSD.org) Date: Sun, 14 Jul 2002 23:04:30 +0300 From: Giorgos Keramidas To: "Balaji, Pavan" Cc: "'freebsd-questions@freebsd.org'" Subject: Re: argc/argv in bash! Message-ID: <20020714200430.GB37859@hades.hell.gr> References: <3D386AED1B47D411A94300508B11F18703BC5BA4@fmsmsx116.fm.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3D386AED1B47D411A94300508B11F18703BC5BA4@fmsmsx116.fm.intel.com> X-Operating-System: FreeBSD 5.0-CURRENT i386 X-PGP-Fingerprint: C1EB 0653 DB8B A557 3829 00F9 D60F 941A 3186 03B6 X-Phone: +30-944-116520 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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