command substitution error using bash

command substitution error using bash

am 23.01.2008 23:39:19 von paintedjazz

I'm getting a command substitution error at the end of a fairly
complex case statement and I'm not sure why. I've looked at the code
over and and I don't see why it's complaining especially since the
results are almost perfect. I say "almost" because it was one little
problem that led me to search the log file.

The actual error is:
command substitution: line 18: syntax error near unexpected token `;;'

I don't quite get the "line 18" since using 'set number' in vi gives
me line 1891 at the beginning of the case statement.

Below is the actual case statement in full. I didn't include more
since it is so lengthy as it is but let me know if any other code
might be helpful. In short, the case statement simply calls a
function (compare_floating_points) to determine whether the aspect
ratio of a given image is greater than, less than or equal to 1.333.
In the log file, the error occurs following the 'rm $TEMP_IMAGE"' in
the branch to 'gt)'.

Thanks for any help.

--
case $(compare_floating_points "$ASPECT_RATIO" 1.333) in
gt) H=$( echo 'scale=3;' $(( $W * 3 )) '/4' |bc #
H=W*(3/4)
H="${H%.*}"
if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
[ "$W" -gt "$SLIDESHOW_WIDTH" ] ; then
#
TEMP_IMAGE=/tmp/"${IMAGE##*/}"
# -p = --padToHeightWidth pixelsH pixelsW
(sips -p "$H" "$W" "$IMAGE" -o "$TEMP_IMAGE") > /
dev/null
#
# -Z = --resampleHeightWidthMax pixelsWH
(sips -Z "$SLIDESHOW_WIDTH" "$TEMP_IMAGE" -o
"$LANDSCAPE") \
> /dev/null
#
rm "$TEMP_IMAGE"
else
#
# -p = --padToHeightWidth pixelsH pixelsW
(sips -p "$H" "$W" "$IMAGE" -o "$LANDSCAPE") > /dev/
null
fi
;;
lt) W=$( echo 'scale=3;' $(( $H * 4 )) '/3' |bc ) #
W=H*(4/3) W="${W%.*}"
if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
[ "$W" -gt "$SLIDESHOW_WIDTH" ] ; then
# TEMP_IMAGE=/tmp/"${IMAGE##*/}"
# -p = --padToHeightWidth pixelsH pixelsW
(sips -p "$H" "$W" "$IMAGE" -o "$TEMP_IMAGE") > /
dev/null
#
# -Z = --resampleHeightWidthMax pixelsWH
(sips -Z "$SLIDESHOW_WIDTH" "$TEMP_IMAGE" -o
"$LANDSCAPE") \
> /dev/null
# rm "$TEMP_IMAGE"
else
#
# -p = --padToHeightWidth pixelsH
pixelsW (sips -p "$H" "$W" "$IMAGE" -o "$LANDSCAPE")
> /dev/null
fi
;;
eq) if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
[ "$W" -gt "$SLIDESHOW_WIDTH" ] ; then
TEMP_IMAGE="/tmp/${IMAGE##*/}"
cp "$IMAGE" /tmp
#
# -Z = --resampleHeightWidthMax pixelsWH
(sips -Z "$SLIDESHOW_WIDTH" "$TEMP_IMAGE" -o
"$LANDSCAPE") \
> /dev/null
#
rm "$TEMP_IMAGE"
else
cp "$IMAGE" "$LANDSCAPE"
fi
;;
esac

Re: command substitution error using bash

am 24.01.2008 02:34:31 von bmynars

Entire thing is a bit messy. However, take a closer look at this line
in your case statement:

gt) H=$( echo 'scale=3;' $(( $W * 3 )) '/4' |bc

Does anything jump right at you? You are missing a right parenthesis
in your command substitution. Also, why are you mixing the
expressions in your 'echo' statement the way you do? It just makes it
look untidy. It would look much cleaner by simply doing:

echo "scale=3; $(( $W * 3 / 4))" | bc
or better yet:

printf "%.3f\n" "$(( $W * 3 / 4 ))"

Simplify, simplify, and simplify. Avoid expensive external calls as
much as you can.

On Jan 23, 5:39 pm, paintedj...@gmail.com wrote:
> I'm getting a command substitution error at the end of a fairly
> complex case statement and I'm not sure why. I've looked at the code
> over and and I don't see why it's complaining especially since the
> results are almost perfect. I say "almost" because it was one little
> problem that led me to search the log file.
>
> The actual error is:
> command substitution: line 18: syntax error near unexpected token `;;'
>
> I don't quite get the "line 18" since using 'set number' in vi gives
> me line 1891 at the beginning of the case statement.
>
> Below is the actual case statement in full. I didn't include more
> since it is so lengthy as it is but let me know if any other code
> might be helpful. In short, the case statement simply calls a
> function (compare_floating_points) to determine whether the aspect
> ratio of a given image is greater than, less than or equal to 1.333.
> In the log file, the error occurs following the 'rm $TEMP_IMAGE"' in
> the branch to 'gt)'.
>
> Thanks for any help.
>
> --
> case $(compare_floating_points "$ASPECT_RATIO" 1.333) in
> gt) H=$( echo 'scale=3;' $(( $W * 3 )) '/4' |bc #
> H=W*(3/4)
> H="${H%.*}"
> if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> [ "$W" -gt "$SLIDESHOW_WIDTH" ] ; then
> #
> TEMP_IMAGE=/tmp/"${IMAGE##*/}"
> # -p = --padToHeightWidth pixelsH pixelsW
> (sips -p "$H" "$W" "$IMAGE" -o "$TEMP_IMAGE") > /
> dev/null
> #
> # -Z = --resampleHeightWidthMax pixelsWH
> (sips -Z "$SLIDESHOW_WIDTH" "$TEMP_IMAGE" -o
> "$LANDSCAPE") \
> > /dev/null
> #
> rm "$TEMP_IMAGE"
> else
> #
> # -p = --padToHeightWidth pixelsH pixelsW
> (sips -p "$H" "$W" "$IMAGE" -o "$LANDSCAPE") > /dev/
> null
> fi
> ;;
> lt) W=$( echo 'scale=3;' $(( $H * 4 )) '/3' |bc ) #
> W=H*(4/3) W="${W%.*}"
> if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> [ "$W" -gt "$SLIDESHOW_WIDTH" ] ; then
> # TEMP_IMAGE=/tmp/"${IMAGE##*/}"
> # -p = --padToHeightWidth pixelsH pixelsW
> (sips -p "$H" "$W" "$IMAGE" -o "$TEMP_IMAGE") > /
> dev/null
> #
> # -Z = --resampleHeightWidthMax pixelsWH
> (sips -Z "$SLIDESHOW_WIDTH" "$TEMP_IMAGE" -o
> "$LANDSCAPE") \
> > /dev/null
> # rm "$TEMP_IMAGE"
> else
> #
> # -p = --padToHeightWidth pixelsH
> pixelsW (sips -p "$H" "$W" "$IMAGE" -o "$LANDSCAPE")> /dev/null
>
> fi
> ;;
> eq) if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> [ "$W" -gt "$SLIDESHOW_WIDTH" ] ; then
> TEMP_IMAGE="/tmp/${IMAGE##*/}"
> cp "$IMAGE" /tmp
> #
> # -Z = --resampleHeightWidthMax pixelsWH
> (sips -Z "$SLIDESHOW_WIDTH" "$TEMP_IMAGE" -o
> "$LANDSCAPE") \
> > /dev/null
> #
> rm "$TEMP_IMAGE"
> else
> cp "$IMAGE" "$LANDSCAPE"
> fi
> ;;
> esac

Re: command substitution error using bash

am 24.01.2008 02:56:47 von bmynars

I went a bit more through your code and some of this just is a little
'weird'. However, take a look at this snippet:

W=H*(4/3)

Since when BASH allows for arithmetic expression the way you do it
above? It should be at least written as:

W=$((H*(4/3)) and whatever H evaluates to (did you declare H as
integer?).

Or is it an arithmetic expression or simply you assign "H*(4/4)" to
W? If that's the case, it should be protected with quotes:

W="H*(4/3)".

I would recommend you to take another look at what you're doing.

On Jan 23, 8:34 pm, "--==[ bman ]==--" wrote:
> Entire thing is a bit messy. However, take a closer look at this line
> in your case statement:
>
> gt) H=$( echo 'scale=3;' $(( $W * 3 )) '/4' |bc
>
> Does anything jump right at you? You are missing a right parenthesis
> in your command substitution. Also, why are you mixing the
> expressions in your 'echo' statement the way you do? It just makes it
> look untidy. It would look much cleaner by simply doing:
>
> echo "scale=3; $(( $W * 3 / 4))" | bc
> or better yet:
>
> printf "%.3f\n" "$(( $W * 3 / 4 ))"
>
> Simplify, simplify, and simplify. Avoid expensive external calls as
> much as you can.
>
> On Jan 23, 5:39 pm, paintedj...@gmail.com wrote:
>
> > I'm getting a command substitution error at the end of a fairly
> > complex case statement and I'm not sure why. I've looked at the code
> > over and and I don't see why it's complaining especially since the
> > results are almost perfect. I say "almost" because it was one little
> > problem that led me to search the log file.
>
> > The actual error is:
> > command substitution: line 18: syntax error near unexpected token `;;'
>
> > I don't quite get the "line 18" since using 'set number' in vi gives
> > me line 1891 at the beginning of the case statement.
>
> > Below is the actual case statement in full. I didn't include more
> > since it is so lengthy as it is but let me know if any other code
> > might be helpful. In short, the case statement simply calls a
> > function (compare_floating_points) to determine whether the aspect
> > ratio of a given image is greater than, less than or equal to 1.333.
> > In the log file, the error occurs following the 'rm $TEMP_IMAGE"' in
> > the branch to 'gt)'.
>
> > Thanks for any help.
>
> > --
> > case $(compare_floating_points "$ASPECT_RATIO" 1.333) in
> > gt) H=$( echo 'scale=3;' $(( $W * 3 )) '/4' |bc #
> > H=W*(3/4)
> > H="${H%.*}"
> > if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> > [ "$W" -gt "$SLIDESHOW_WIDTH" ] ; then
> > #
> > TEMP_IMAGE=/tmp/"${IMAGE##*/}"
> > # -p = --padToHeightWidth pixelsH pixelsW
> > (sips -p "$H" "$W" "$IMAGE" -o "$TEMP_IMAGE") > /
> > dev/null
> > #
> > # -Z = --resampleHeightWidthMax pixelsWH
> > (sips -Z "$SLIDESHOW_WIDTH" "$TEMP_IMAGE" -o
> > "$LANDSCAPE") \
> > > /dev/null
> > #
> > rm "$TEMP_IMAGE"
> > else
> > #
> > # -p = --padToHeightWidth pixelsH pixelsW
> > (sips -p "$H" "$W" "$IMAGE" -o "$LANDSCAPE") > /dev/
> > null
> > fi
> > ;;
> > lt) W=$( echo 'scale=3;' $(( $H * 4 )) '/3' |bc ) #
> > W=H*(4/3) W="${W%.*}"
> > if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> > [ "$W" -gt "$SLIDESHOW_WIDTH" ] ; then
> > # TEMP_IMAGE=/tmp/"${IMAGE##*/}"
> > # -p = --padToHeightWidth pixelsH pixelsW
> > (sips -p "$H" "$W" "$IMAGE" -o "$TEMP_IMAGE") > /
> > dev/null
> > #
> > # -Z = --resampleHeightWidthMax pixelsWH
> > (sips -Z "$SLIDESHOW_WIDTH" "$TEMP_IMAGE" -o
> > "$LANDSCAPE") \
> > > /dev/null
> > # rm "$TEMP_IMAGE"
> > else
> > #
> > # -p = --padToHeightWidth pixelsH
> > pixelsW (sips -p "$H" "$W" "$IMAGE" -o "$LANDSCAPE")> /dev/null
>
> > fi
> > ;;
> > eq) if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> > [ "$W" -gt "$SLIDESHOW_WIDTH" ] ; then
> > TEMP_IMAGE="/tmp/${IMAGE##*/}"
> > cp "$IMAGE" /tmp
> > #
> > # -Z = --resampleHeightWidthMax pixelsWH
> > (sips -Z "$SLIDESHOW_WIDTH" "$TEMP_IMAGE" -o
> > "$LANDSCAPE") \
> > > /dev/null
> > #
> > rm "$TEMP_IMAGE"
> > else
> > cp "$IMAGE" "$LANDSCAPE"
> > fi
> > ;;
> > esac

Re: command substitution error using bash

am 24.01.2008 06:25:56 von paintedjazz

On Jan 23, 5:34=A0pm, "--==[ bman ]==--" wrote:
> Entire thing is a bit messy. =A0However, take a closer look at this line
> in your case statement:
>
> gt) H=3D$( echo 'scale=3D3;' $(( $W * 3 )) '/4' |bc
>
> Does anything jump right at you? =A0You are missing a right parenthesis
> in your command substitution. =A0Also, why are you mixing the
> expressions in your 'echo' statement the way you do? =A0It just makes it
> look untidy. =A0It would look much cleaner by simply doing:
>
> echo "scale=3D3; $(( $W * 3 =A0/ 4))" | bc
> or better yet:
>
> printf "%.3f\n" "$(( $W * 3 / 4 ))"
>
> Simplify, simplify, and simplify. =A0Avoid expensive external calls as
> much as you can.

Hey, thanks! That really solved the problem! And thanks for the
better written code -- I already implemented it with the printf and
the syntax errors are gone.


> On Jan 23, 5:39 pm, paintedj...@gmail.com wrote:
>
> > I'm getting a command substitution error at the end of a fairly
> > complex case statement and I'm not sure why. =A0I've looked at the code
> > over and and I don't see why it's complaining especially since the
> > results are almost perfect. =A0I say "almost" because it was one little
> > problem that led me to search the log file.
>
> > The actual error is:
> > command substitution: line 18: syntax error near unexpected token `;;'
>
> > I don't quite get the "line 18" since using 'set number' in vi gives
> > me line 1891 at the beginning of the case statement.
>
> > Below is the actual case statement in full. =A0I didn't include more
> > since it is so lengthy as it is but let me know if any other code
> > might be helpful. =A0In short, the case statement simply calls a
> > function (compare_floating_points) to determine whether the aspect
> > ratio of a given image is greater than, less than or equal to 1.333.
> > In the log file, the error occurs following the 'rm $TEMP_IMAGE"' in
> > the branch to 'gt)'.
>
> > Thanks for any help.
>
> > --
> > =A0 =A0 =A0 =A0 =A0case $(compare_floating_points "$ASPECT_RATIO" 1.333)=
in
> > =A0 =A0 =A0 =A0 =A0 =A0 gt) H=3D$( echo 'scale=3D3;' $(( $W * 3 )) '/4' =
|bc =A0 =A0 #
> > H=3DW*(3/4)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 H=3D"${H%.*}"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0[ "$W" -gt "$SLIDESHOW_WIDTH" ] ;=
then
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TEMP_IMAGE=3D/tmp/"${IMAGE##*/}"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -p =3D --padToHeightWidth pixel=
sH pixelsW
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -p "$H" "$W" "$IMAGE" -o "$=
TEMP_IMAGE") > /
> > dev/null
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -Z =3D --resampleHeightWidthMax=
pixelsWH
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -Z "$SLIDESHOW_WIDTH" "$TEM=
P_IMAGE" -o
> > "$LANDSCAPE") \
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0> /dev/null
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rm "$TEMP_IMAGE"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -p =3D --padToHeightWidth pixel=
sH pixelsW
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -p "$H" "$W" "$IMAGE" -o "$=
LANDSCAPE") > /dev/
> > null
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;;
> > =A0 =A0 =A0 =A0 =A0 =A0 lt) W=3D$( echo 'scale=3D3;' $(( $H * 4 )) '/3' =
|bc ) =A0 =A0 #
> > W=3DH*(4/3) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0W=3D"${W%.*}"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0[ "$W" -gt "$SLIDESHOW_WIDTH" ] ;=
then
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 TEMP_IMAGE=3D/tmp/"${IMAGE##*/}"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -p =3D --padToHeightWidth pixel=
sH pixelsW
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -p "$H" "$W" "$IMAGE" -o "$=
TEMP_IMAGE") > /
> > dev/null
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -Z =3D --resampleHeightWidthMax=
pixelsWH
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -Z "$SLIDESHOW_WIDTH" "$TEM=
P_IMAGE" -o
> > "$LANDSCAPE") \
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0> /dev/null
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0rm "$TEMP_IMAGE"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -p =3D --padToHeightWidth pixel=
sH
> > pixelsW =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (sips -p "$H" "$W" "$IMAGE" =
-o "$LANDSCAPE")> /dev/null
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;;
> > =A0 =A0 =A0 =A0 =A0 =A0 eq) if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0[ "$W" -gt "$SLIDESHOW_WIDTH" ] ;=
then
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TEMP_IMAGE=3D"/tmp/${IMAGE##*/}"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cp "$IMAGE" /tmp
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -Z =3D --resampleHeightWidthMax=
pixelsWH
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -Z "$SLIDESHOW_WIDTH" "$TEM=
P_IMAGE" -o
> > "$LANDSCAPE") \
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0> /dev/null
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rm "$TEMP_IMAGE"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cp "$IMAGE" "$LANDSCAPE"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;;
> > =A0 =A0 =A0 =A0 =A0esac

Re: command substitution error using bash

am 24.01.2008 06:28:44 von paintedjazz

On Jan 23, 5:56=A0pm, "--==[ bman ]==--" wrote:
> I went a bit more through your code and some of this just is a little
> 'weird'. =A0However, take a look at this snippet:
>
> W=3DH*(4/3)

That was actually a comment but, because my code was indented,
the cut & paste made a lot of it wrap so you probably didn't see that
it was actually a comment.


> Since when BASH allows for arithmetic expression the way you do it
> above? =A0It should be at least written as:
>
> W=3D$((H*(4/3)) and whatever H evaluates to (did you declare H as
> integer?).
>
> Or is it an arithmetic expression or simply you assign "H*(4/4)" to
> W? =A0If that's the case, it should be protected with quotes:
>
> W=3D"H*(4/3)".
>
> I would recommend you to take another look at what you're doing.
>
> On Jan 23, 8:34 pm, "--==[ bman ]==--" wrote:
>
> > Entire thing is a bit messy. =A0However, take a closer look at this line=

> > in your case statement:
>
> > gt) H=3D$( echo 'scale=3D3;' $(( $W * 3 )) '/4' |bc
>
> > Does anything jump right at you? =A0You are missing a right parenthesis
> > in your command substitution. =A0Also, why are you mixing the
> > expressions in your 'echo' statement the way you do? =A0It just makes it=

> > look untidy. =A0It would look much cleaner by simply doing:
>
> > echo "scale=3D3; $(( $W * 3 =A0/ 4))" | bc
> > or better yet:
>
> > printf "%.3f\n" "$(( $W * 3 / 4 ))"
>
> > Simplify, simplify, and simplify. =A0Avoid expensive external calls as
> > much as you can.
>
> > On Jan 23, 5:39 pm, paintedj...@gmail.com wrote:
>
> > > I'm getting a command substitution error at the end of a fairly
> > > complex case statement and I'm not sure why. =A0I've looked at the cod=
e
> > > over and and I don't see why it's complaining especially since the
> > > results are almost perfect. =A0I say "almost" because it was one littl=
e
> > > problem that led me to search the log file.
>
> > > The actual error is:
> > > command substitution: line 18: syntax error near unexpected token `;;'=

>
> > > I don't quite get the "line 18" since using 'set number' in vi gives
> > > me line 1891 at the beginning of the case statement.
>
> > > Below is the actual case statement in full. =A0I didn't include more
> > > since it is so lengthy as it is but let me know if any other code
> > > might be helpful. =A0In short, the case statement simply calls a
> > > function (compare_floating_points) to determine whether the aspect
> > > ratio of a given image is greater than, less than or equal to 1.333.
> > > In the log file, the error occurs following the 'rm $TEMP_IMAGE"' in
> > > the branch to 'gt)'.
>
> > > Thanks for any help.
>
> > > --
> > > =A0 =A0 =A0 =A0 =A0case $(compare_floating_points "$ASPECT_RATIO" 1.33=
3) in
> > > =A0 =A0 =A0 =A0 =A0 =A0 gt) H=3D$( echo 'scale=3D3;' $(( $W * 3 )) '/4=
' |bc =A0 =A0 #
> > > H=3DW*(3/4)
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 H=3D"${H%.*}"
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || =
\
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0[ "$W" -gt "$SLIDESHOW_WIDTH" ]=
; then
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TEMP_IMAGE=3D/tmp/"${IMAGE##*/}=
"
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -p =3D --padToHeightWidth pix=
elsH pixelsW
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -p "$H" "$W" "$IMAGE" -o =
"$TEMP_IMAGE") > /
> > > dev/null
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -Z =3D --resampleHeightWidthM=
ax pixelsWH
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -Z "$SLIDESHOW_WIDTH" "$T=
EMP_IMAGE" -o
> > > "$LANDSCAPE") \
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0> /dev/null
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rm "$TEMP_IMAGE"
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -p =3D --padToHeightWidth pix=
elsH pixelsW
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -p "$H" "$W" "$IMAGE" -o =
"$LANDSCAPE") > /dev/
> > > null
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;;
> > > =A0 =A0 =A0 =A0 =A0 =A0 lt) W=3D$( echo 'scale=3D3;' $(( $H * 4 )) '/3=
' |bc ) =A0 =A0 #
> > > W=3DH*(4/3) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0W=3D"${W%.*}"
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || =
\
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0[ "$W" -gt "$SLIDESHOW_WIDTH" ]=
; then
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 TEMP_IMAGE=3D/tmp/"${IMAGE##*/}"
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -p =3D --padToHeightWidth pix=
elsH pixelsW
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -p "$H" "$W" "$IMAGE" -o =
"$TEMP_IMAGE") > /
> > > dev/null
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -Z =3D --resampleHeightWidthM=
ax pixelsWH
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -Z "$SLIDESHOW_WIDTH" "$T=
EMP_IMAGE" -o
> > > "$LANDSCAPE") \
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0> /dev/null
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0rm "$TEMP_IMAGE"
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -p =3D --padToHeightWidth pix=
elsH
> > > pixelsW =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (sips -p "$H" "$W" "$IMAGE=
" -o "$LANDSCAPE")> /dev/null
>
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;;
> > > =A0 =A0 =A0 =A0 =A0 =A0 eq) if [ "$H" -gt "$SLIDESHOW_WIDTH" ] || \
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0[ "$W" -gt "$SLIDESHOW_WIDTH" ]=
; then
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TEMP_IMAGE=3D"/tmp/${IMAGE##*/}=
"
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cp "$IMAGE" /tmp
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# -Z =3D --resampleHeightWidthM=
ax pixelsWH
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(sips -Z "$SLIDESHOW_WIDTH" "$T=
EMP_IMAGE" -o
> > > "$LANDSCAPE") \
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0> /dev/null
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rm "$TEMP_IMAGE"
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cp "$IMAGE" "$LANDSCAPE"
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fi
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;;
> > > =A0 =A0 =A0 =A0 =A0esac

Re: command substitution error using bash

am 24.01.2008 17:18:40 von Icarus Sparry

On Wed, 23 Jan 2008 14:39:19 -0800, paintedjazz wrote:

> I'm getting a command substitution error at the end of a fairly complex
> case statement and I'm not sure why. I've looked at the code over and
> and I don't see why it's complaining especially since the results are
> almost perfect. I say "almost" because it was one little problem that
> led me to search the log file.
[snip]

>
> Thanks for any help.
>
> --
> case $(compare_floating_points "$ASPECT_RATIO" 1.333) in
> gt) H=$( echo 'scale=3;' $(( $W * 3 )) '/4' |bc #H=W*(3/4)

Others have already pointed out your error. You might find that writing
your case statement as

case $(...) in
(gt) .... ;;

i.e. putting a ( before the item, will enable you to use whatever bracket
matching functions you have in your editor to work a lot better.