delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/10/31/20:42:51

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RP_MATCHES_RCVD,SPF_HELO_PASS
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Andrew DeFaria <Andrew AT DeFaria DOT com>
Subject: Re: Command line arguments
Date: Wed, 31 Oct 2012 12:15:38 -0700
Lines: 16
Message-ID: <k6rtcp$fo8$1@ger.gmane.org>
References: <1351606847888-94081 DOT post AT n5 DOT nabble DOT com> <20121031182143 DOT M67652 AT ds DOT net>
Mime-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
In-Reply-To: <20121031182143.M67652@ds.net>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 10/31/2012 11:23 AM, Brian Wilson wrote:
> If you have a script (e.g. foo.sh) and you wish to pass arguments to the
> script, your command line should look like "foo.sh arg1 arg2 arg3..."  The
> number of arguments will be correct and you will be able to access them as
> ${1}, ${2}, etc.  Also, you may want to read up on the getopts command as a
> way to process command line arguments.
Technically, the {}'s are not needed. You can access them with $1, $2, 
etc. Most special characters sever as delimiters too so you can refer to 
them as "This the $1 parameter" or even "/path/to/$1/dir". But if you 
wanted to do something like this - "This is the ${1}parameter" or even 
"/path/to/$1.save/dir" but not "/path/to/$1save/dir" you'd need the {} 
(i.e. "/path/to/${1}save/dir" because otherwise the shell would be 
looking for "1save" as an env variable name.
-- 
Andrew DeFaria <http://defaria.com>
Fear has its use but cowardice has none. - Mohandas Gandhi


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019