This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Command line arguments


On 10/31/2012 12:40 PM, David T-G wrote:
Andrew, et al --

...and then Andrew DeFaria said...
%
% On 10/31/2012 11:23 AM, Brian Wilson wrote:
...
% >${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 :-)
I was thinking that and should have tested it... Sorry if there was any confusion there.

davidtg@madi:~ > cat /tmp/numvars.sh bash --version save=x echo $save 1save=y echo $1save echo ${1save} davidtg@madi:~ > bash -x /tmp/numvars.sh + bash --version GNU bash, version 2.05a.0(1)-release (i386-portbld-freebsd4.6) Copyright 2001 Free Software Foundation, Inc.
Interesting bash version there:

   $ bash --version
   GNU bash, version 4.1.10(4)-release (i686-pc-cygwin)
   Copyright (C) 2009 Free Software Foundation, Inc.
   License GPLv3+: GNU GPL version 3 or later
   <http://gnu.org/licenses/gpl.html>

   This is free software; you are free to change and redistribute it.
   There is NO WARRANTY, to the extent permitted by law.

You seem to be a bit behind...
   + save=x
   + echo x
   x
   + 1save=y
   /tmp/numvars.sh: 1save=y: command not found
   + echo save
   save
   /tmp/numvars.sh: ${1save}: bad substitution


% -- % Andrew DeFaria <http://defaria.com> % Fear has its use but cowardice has none. - Mohandas Gandhi


HTH & Happy Hallowe'en


:-D


--
Andrew DeFaria <http://defaria.com>
When everything's coming your way, you're in the wrong lane.


-- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]