[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 18:25:37 -0600 |
> In any case, combining a command and its arguments in a single
> string is almost always the wrong way to go about it.
Please compare the two scripts and see if the second one makes more sense.
/tmp$ cat not_convert_args_to_string.sh
#!/bin/bash
options="$2"
find $1 $options
echo find $1 $options
/tmp$ cat convert_args_to_string.sh
#!/bin/bash
options="$2"
cmd="find $1 $options"
eval "$cmd"
echo $cmd
/tmp$ ./not_convert_args_to_string.sh . "-type f -name '*'"
find: `./cvcd': Permission denied
find . -type f -name '*'
/tmp$ ./convert_args_to_string.sh . "-type f -name '*'"|head
find: `./cvcd': Permission denied
./.main.sh.swp
./0001e4ecf6175
./alm.log
./amt.log
./convert_args_to_string.sh
./FLEXnet/11.5.0.0 build 56285Macrovision
./FLEXnet/524288-16F7558F-328B-4dc3-BEDF-095C1F14FFF1
./FLEXnet/524288-34E9EE98-50ED-4c6c-BD0F-F539123FD064
./FLEXnet/524288-85A0F138-527D-4012-8175-79A3AEA4152E
./FLEXnet/freCqflgCxFrwiBvBiCadibCwg
--
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 <=
- 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, 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