fmw42 wrote:Try this to remove any line feeds from the convert command
width=$(convert rose: -format "%w" info: | tr -d "\n")
echo "width=${width}"
xx=$((width-1))
echo "xx=${xx}"
The extra newline is normal, and most programs generate it... including "bc". In this case it is generated because info: will always add a newline after processing
-format once for each image.
For example...
Code: Select all
convert rose: logo: -format "%w" info:
70
640
If the newline was not added you would have gotten "70640" This is historical, and for ease of use for users, otherwise the
-format setting needs a "\n" added to the format string.
An alternative is use
-print, whcih does not add extra chars as it is applied once only (even with multiple images)
Code: Select all
convert rose: logo: -print "%w" null:
70
Note there is no extra newline in the above though it is hard to demonstrate that on the forum.
Hmmm the
$(....) shell syntax seems to automatically strip extra newlines!
Code: Select all
> width=$(convert rose: -format '%w\n\n\n' info:)
> echo "$width"
70
>
That is strange as the bash manual clearly states...
Embedded newlines are not deleted, but they may be removed during word splitting.
Adding a extra character after the newlines "\n" however did casue the newline to be retained.
Code: Select all
> width=$(convert rose: -format '%w\n\n\nA' info:)
> echo "$width"
70
A
So it looks like newlines on the end in my version of bash are stripped automatically. adding more newlines after the "A" in the last example were also striped, though the ones in between were retained.
However, shell integer arithmetic expression handling should also ignore white space, including newlines. For example...
Code: Select all
width="100
"
echo "width=${width}"
xx=$(( width - 1 ))
echo "xx=${xx}"
Perhaps your BASH is too old for $((..)) or it isn't BASH at all but simpler Bourne (Posix) shell!
hmmm... "Dash" on Linux systems is a Posix Shell (with saome berkley extensions), though it has $((...)) too,
and works as expected.
Trying old Solaris Bourne Shell "sh" (Sun/Oracle UNIX machine) gives me the error
syntax error: `xx=$' unexpected
While "zsh", "ksh", works fine.
So really what version of BASH is cygwin using???? Must be pretty old.
Can you try the above tests?
My version is
Code: Select all
bash --version
GNU bash, version 4.2.37(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2011 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.