X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org From: "Brian Wilson" To: David T-G , "CygWin Users' List" Subject: Re: Command line arguments Date: Thu, 1 Nov 2012 12:54:43 -0500 Message-Id: <20121101174144.M43908@ds.net> In-Reply-To: <20121031194051.GL67410@justpickone.org> References: <1351606847888-94081 DOT post AT n5 DOT nabble DOT com> <20121031182143 DOT M67652 AT ds DOT net> <20121031194051 DOT GL67410 AT justpickone DOT org> X-OriginatingIP: 158.111.236.102 (wilson) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com > > % >${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, ... % > > "/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. > > ... except that environment variables cannot begin with numbers :-) > True, but that won't keep the system from trying to interpret the string as a variable and erroring out on something a novice might easily write. I got in the habbit of always using the "{}" (even if they aren't absolutely necessary) to avoid such issues on general principal. It can also help keep things straight if you want to do something like the following line in a script 'VAR="${VAR}${VAR:+, }${VAR2}"' in a loop to create a comma-space separated string. The first time through the loop, VAR is NULL and won't add anything to the string so only VAR2's value is assigned to VAR. The next time through VAR is defined and will have "${VAR}, ${VAR2}" assigned back to VAR. It's faster and cleaner than using an IF statement to do the same task. -- 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