This is the mail archive of the
mailing list for the Cygwin project.
Re: sftp progress showing ... 66% complete
- From: Eric Blake <ebb9 at byu dot net>
- To: Robert Body <rbody99 at hotmail dot com>, cygwin at cygwin dot com
- Date: Sat, 10 Dec 2005 14:36:55 -0700
- Subject: Re: sftp progress showing ... 66% complete
- References: <BAY104-F18D8486CB6C9EB7925EBE0AD440@phx.gbl>
- Reply-to: cygwin at cygwin dot com
-----BEGIN PGP SIGNED MESSAGE-----
Ugh - top-posted. Reformatted. http://cygwin.com/acronyms/#TOFU
>> From: Eric Blake <ebb9 AT byu DOT net>
Ugh - http://cygwin.com/acronyms/#PCYMTNQREAIYR
> If you use bash, $(( x - y )) does just that.
>> (nor how to get
>> clock-ticks since 1970/1/1)
> date +%s
According to Robert Body on 12/10/2005 2:23 PM:
> Thanks Eric, that does the trick, it's short and interesting syntax with
> ((x-y)), i tried (x-y) before myself, i didn't think of trying double
> /home/Owner/r> start=$(date +%s)
> /home/Owner/r> end=$(date +%s)
> /home/Owner/r> (($end-$start))
> /home/Owner/r> alpha=$(($end-$start)); echo $alpha
> how come straight out (($end-$start)) doesn't work, i have to assign it
> to a variable?
The syntax for arithmetic substitution is $(( expression )). It is
required by POSIX shells, and all it does is replace everything from the
starting $(( to the ending )) with the string result, provided the
expression could be evaluated. (($end-$start)) is a bash extension which
is only used to test the result for 0/non-zero, rather than actually
providing the result in the text of the rest of the line.
> with some playing:
> /home/Owner/r> echo (($end-$start))
> bash: syntax error near unexpected token `('
Because (( )) only makes sense as an entire command, not as an argument to
some other command.
> /home/Owner/r> echo `(($end-$start))`
Because (()) was used as an entire command, but produced no output, so the
`` was invoked with no input, and produced no output, so echo just printed
> /home/Owner/r> echo `($end-$start)`
> bash: 1134249426-1134249416: command not found
Because () invokes a subshell, rather than arithmetic substitution, and as
bash told you, there really isn't a command by that name.
> /home/Owner/r> echo $(($end-$start))
I would suggest reading up on 'man bash'.
> too bad it's not a standard way that would work in anything, sh, ksh,
> how would ksh syntax look like?
If your shell is POSIX-compliant (cygwin's /bin/sh, bash, ksh, and zsh all
have POSIX-compliant behavior, but ash does not), then $(( )) will work.
If you want to be portable to older hosts or shells, consider reading up
on 'man expr' (shell arithmetic substitution was designed to be more
efficient than what expr could do).
Life is short - so eat dessert first!
Eric Blake email@example.com
volunteer cygwin bash maintainer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html