sh question: commands as variables / stream operators in a variable

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Wed Jul 11 18:02:43 UTC 2007


On Wed, Jul 11, 2007 at 02:30:04PM +0200, Christopher Friedt wrote:
> ah got it ;-)
> 
> #!/bin/sh
> 
> echo 'Hello World!' > test.txt
> CMD="cat test.txt"
> OUTFILE="test2.txt"
> 
> # COMP can be one of '', 'bzip2', 'gzip'
> COMP="bzip2"
> COMP_CMD=""
> case "$COMP" in
> ("bzip2")
>   COMP_CMD="| bzip2 -9"
>   OUTFILE="${OUTFILE}.bz2"
> ;;
> ("gzip")
>   COMP_CMD="| gzip -c -9"
>   OUTFILE="${OUTFILE}.gz"
> ;;
> ("")
>   COMP_CMD=""
> ;;
> (*)
> exit 1
> ;;
> esac
> 
> CMD="${CMD} ${COMP_CMD} > ${OUTFILE}"
> ${SHELL} -c "${CMD}"
> exit $?

Have about:
eval ${CMD}

--
Len Sorensen
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list