[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: converting array to string by quoting each element for eval
From: |
Peng Yu |
Subject: |
Re: converting array to string by quoting each element for eval |
Date: |
Tue, 15 Nov 2011 20:24:01 -0600 |
> Then why don't you post that?
Please take a look and see if you have a better solution than the
following code without using quotearg.sh.
/tmp/tmp$ ll *
c d:
total 0
-rw-r--r-- 1 pengy wheel 0 2011-11-15 20:18:11 xx
a b:
total 0
-rw-r--r-- 1 pengy wheel 0 2011-11-15 20:18:15 yy
/tmp/tmp$ ../convert_args_to_string.sh 'a b' 'c d' -O "-type f -name '*'"
TEMP= -O '-type f -name '\''*'\''' -- 'a b' 'c d'
a b/yy
c d/xx
find 'a b' 'c d' -type f -name '*'
/tmp/tmp$ cat ../convert_args_to_string.sh
#!/bin/bash
TEMP=`getopt -o O: --long options: -n "${script_name}.sh" -- "$@"`
echo TEMP=$TEMP
if [ $? != 0 ] ; then printf "Terminating...\n" >&2 ; exit 1 ; fi
eval set -- "$TEMP"
abspath_script=`readlink -f -e "$0"`
script_absdir=`dirname "$abspath_script"`
while true ; do
case "$1" in
-O|--options)
options="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Internal error!"
exit 1
;;
esac
done
arg_string=`quotearg.sh "$@"`
cmd="find $arg_string $options"
eval "$cmd"
echo $cmd
--
Regards,
Peng
- converting array to string by quoting each element for eval, Peng Yu, 2011/11/15
- Re: converting array to string by quoting each element for eval, Chris F.A. Johnson, 2011/11/15
- Re: converting array to string by quoting each element for eval, Peng Yu, 2011/11/15
- Re: converting array to string by quoting each element for eval, Chris F.A. Johnson, 2011/11/15
- Re: converting array to string by quoting each element for eval, Peng Yu, 2011/11/15
- Re: converting array to string by quoting each element for eval, Chris F.A. Johnson, 2011/11/15
- Re: converting array to string by quoting each element for eval, Peng Yu, 2011/11/15
- Re: converting array to string by quoting each element for eval, Chris F.A. Johnson, 2011/11/15
- Re: converting array to string by quoting each element for eval,
Peng Yu <=
- Re: converting array to string by quoting each element for eval, Greg Wooledge, 2011/11/16
- Re: converting array to string by quoting each element for eval, Peng Yu, 2011/11/16
- Re: converting array to string by quoting each element for eval, Greg Wooledge, 2011/11/16
- Re: converting array to string by quoting each element for eval, Peng Yu, 2011/11/16
- Re: converting array to string by quoting each element for eval, Peng Yu, 2011/11/16