Re: .sh & getopts

2010-06-06 Thread Matthew Seaman
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 06/06/2010 08:40:56, Aiza wrote: > I have been looking for documentation on freebsd's sh shell programming. > Want to understand what is happening in that getopts I posted. Where can > I find real explanations? Well, the essential reference is the

Re: .sh & getopts

2010-06-06 Thread Aiza
Matthew Seaman wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 06/06/2010 05:57:37, Aiza wrote: i) action="installworld"; flag_count=$((flag_count+1));; Try it like this instead: i) action="installworld"; flag_count=$(( $flag_count + 1 ));; (Obviously, apply the equivalent change

Re: .sh & getopts

2010-06-06 Thread Matthew Seaman
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 06/06/2010 05:57:37, Aiza wrote: > i) action="installworld"; flag_count=$((flag_count+1));; Try it like this instead: i) action="installworld"; flag_count=$(( $flag_count + 1 ));; (Obviously, apply the equivalent change to the other lines)

Re: .sh & getopts

2010-06-06 Thread Matthew Seaman
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 06/06/2010 02:47:38, Dan Nelson wrote: >> flag_count=`expr $flag_count + 1` > /bin/sh can do math on its own: > > flag_count=$((flag_count+1)) flag_count=$(( $flag_count + 1 )) surely? Needs to dereference the variable inside the arithmetic expa

Re: .sh & getopts

2010-06-05 Thread Aiza
Aiza wrote: CyberLeo Kitsana wrote: On 06/05/2010 10:56 PM, Aiza wrote: i) action="installworld"; $flag_count=$((flag_count+1));; ... What is still wrong here Bourne shell expands variables to their contents before evaluating. Thus, the above assignment ends up expanding to '0=1'. Leave ou

Re: .sh & getopts

2010-06-05 Thread Aiza
CyberLeo Kitsana wrote: On 06/05/2010 10:56 PM, Aiza wrote: i) action="installworld"; $flag_count=$((flag_count+1));; ... What is still wrong here Bourne shell expands variables to their contents before evaluating. Thus, the above assignment ends up expanding to '0=1'. Leave out the $ on th

Re: .sh & getopts

2010-06-05 Thread CyberLeo Kitsana
On 06/05/2010 10:56 PM, Aiza wrote: >i) action="installworld"; $flag_count=$((flag_count+1));; > ... > What is still wrong here Bourne shell expands variables to their contents before evaluating. Thus, the above assignment ends up expanding to '0=1'. Leave out the $ on the target variable, and

Re: .sh & getopts

2010-06-05 Thread Aiza
/bin/sh can do math on its own: flag_count=$((flag_count+1)) I want to know if more that one flag has been coded on the command. So add 1 to counter if that flag was processed. After all the flags are processed and fall out of getopts, then check flag counter for value. Ok I coded like th

Re: .sh & getopts

2010-06-05 Thread Dan Nelson
In the last episode (Jun 05), Brandon Gooch said: > On Sat, Jun 5, 2010 at 6:20 PM, Aiza wrote: > > Robert Bonomi wrote: > >>> From: Aiza > >>> Robert Bonomi wrote: > > From: Aiza > > > > Have this code > > > > shift; while getopts :ugr: arg; do case ${arg} in > >    u) a

Re: .sh & getopts

2010-06-05 Thread Brandon Gooch
On Sat, Jun 5, 2010 at 6:20 PM, Aiza wrote: > Robert Bonomi wrote: >>> >>> Date: Sat, 05 Jun 2010 20:51:28 +0800 >>> From: Aiza >>> To: Robert Bonomi >>> Subject: Re: .sh & getopts >>> >>> Robert Bonomi wrote: >>>&

Re: .sh & getopts

2010-06-05 Thread Aiza
Robert Bonomi wrote: Date: Sat, 05 Jun 2010 20:51:28 +0800 From: Aiza To: Robert Bonomi Subject: Re: .sh & getopts Robert Bonomi wrote: From owner-freebsd-questi...@freebsd.org Thu Jun 3 23:36:28 2010 Date: Fri, 04 Jun 2010 12:35:56 +0800 From: Aiza To: "questi...@freebsd

Re: .sh & getopts

2010-06-05 Thread Aiza
Robert Bonomi wrote: m From owner-freebsd-questi...@freebsd.org Thu Jun 3 23:36:28 2010 Date: Fri, 04 Jun 2010 12:35:56 +0800 From: Aiza To: "questi...@freebsd.org" Cc: Subject: .sh & getopts Have this code shift; while getopts :ugr: arg; do case ${arg} in u) action=&

Re: .sh & getopts

2010-06-04 Thread Robert Bonomi
m > From owner-freebsd-questi...@freebsd.org Thu Jun 3 23:36:28 2010 > Date: Fri, 04 Jun 2010 12:35:56 +0800 > From: Aiza > To: "questi...@freebsd.org" > Cc: > Subject: .sh & getopts > > Have this code > > shift; while getopts :ugr: arg; do ca

Re: .sh & getopts

2010-06-04 Thread Aiza
Steve Bertrand wrote: On 2010.06.04 00:35, Aiza wrote: Have this code shift; while getopts :ugr: arg; do case ${arg} in u) action="freebsd-update";; g) action="freebsd-upgrade";; r) action="freebsd-rollback";; ?) exerr ${cmd_usage};; esac; done; shift $(( ${OPTION} -1 )) Comm

Re: .sh & getopts

2010-06-04 Thread Steve Bertrand
On 2010.06.04 00:35, Aiza wrote: > Have this code > > shift; while getopts :ugr: arg; do case ${arg} in >u) action="freebsd-update";; >g) action="freebsd-upgrade";; >r) action="freebsd-rollback";; >?) exerr ${cmd_usage};; > esac; done; shift $(( ${OPTION} -1 )) > > > Command bein

.sh & getopts

2010-06-03 Thread Aiza
Have this code shift; while getopts :ugr: arg; do case ${arg} in u) action="freebsd-update";; g) action="freebsd-upgrade";; r) action="freebsd-rollback";; ?) exerr ${cmd_usage};; esac; done; shift $(( ${OPTION} -1 )) Command being executed looks like this, cmd action -flags bbb