From: laomingliu on
I have the following command which performs a find on the current
directory
and works perfectly:

FILE_COUNT=$( eval 'find . -maxdepth 1' "${OPT}" |wc -l |sed 's/^[ ]
*//' )

However, I now want to modify that command to work not just on the
current directory
but to a variable. However, because the dot (. (the current dir)) is
single quoted,
it failed when I tried:

FILE_COUNT=$( eval 'find' "$FOLDER" '-maxdepth 1' "${OPT}" |wc -l |sed
's/^[ ]*//' )

I thought that I could get away with this, I guess, because "${OPT}"
is double quoted
and works (as in the first variable assignment).

Is it possible to fix this in the way I'm trying to do? How should I
try it?




From: Bill Marcum on

On 2008-12-11, laomingliu(a)gmail.com <laomingliu(a)gmail.com> wrote:
>
>
> I have the following command which performs a find on the current
> directory
> and works perfectly:
>
> FILE_COUNT=$( eval 'find . -maxdepth 1' "${OPT}" |wc -l |sed 's/^[ ]
> *//' )
>
> However, I now want to modify that command to work not just on the
> current directory
> but to a variable. However, because the dot (. (the current dir)) is
> single quoted,
> it failed when I tried:
>
> FILE_COUNT=$( eval 'find' "$FOLDER" '-maxdepth 1' "${OPT}" |wc -l |sed
> 's/^[ ]*//' )
>
> I thought that I could get away with this, I guess, because "${OPT}"
> is double quoted
> and works (as in the first variable assignment).
>
How does it fail? Are you sure you need eval?


> Is it possible to fix this in the way I'm trying to do? How should I
> try it?
>
>
>
>


--
They can't stop us... we're on a mission from God!
-- The Blues Brothers
From: Eric on
On 2008-12-11, laomingliu(a)gmail.com <laomingliu(a)gmail.com> wrote:
>
>
> I have the following command which performs a find on the current
> directory
> and works perfectly:
>
> FILE_COUNT=$( eval 'find . -maxdepth 1' "${OPT}" |wc -l |sed 's/^[ ]
> *//' )
>
> However, I now want to modify that command to work not just on the
> current directory
> but to a variable. However, because the dot (. (the current dir)) is
> single quoted,
> it failed when I tried:
>
> FILE_COUNT=$( eval 'find' "$FOLDER" '-maxdepth 1' "${OPT}" |wc -l |sed
> 's/^[ ]*//' )
>
> I thought that I could get away with this, I guess, because "${OPT}"
> is double quoted
> and works (as in the first variable assignment).
>
> Is it possible to fix this in the way I'm trying to do? How should I
> try it?
>

Don't see why you need the eval at all. And what actually happens with
the new version? And (just in case it matters), which shell is this?
From: Chris F.A. Johnson on
On 2008-12-11, laomingliu(a)gmail.com wrote:
> I have the following command which performs a find on the current
> directory
> and works perfectly:
>
> FILE_COUNT=$( eval 'find . -maxdepth 1' "${OPT}" |wc -l |sed 's/^[ ]
> *//' )
>
> However, I now want to modify that command to work not just on the
> current directory
> but to a variable. However, because the dot (. (the current dir)) is
> single quoted,
> it failed when I tried:
>
> FILE_COUNT=$( eval 'find' "$FOLDER" '-maxdepth 1' "${OPT}" |wc -l |sed
> 's/^[ ]*//' )

Assuming that the find command works (what's in $OPT?):

FILE_COUNT=$(( $(find "$FOLDER" -maxdepth 1 "${OPT}" |wc -l) + 0 ))


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
From: Stephane CHAZELAS on
2008-12-11, 11:07(-08), laomingliu(a)gmail.com:
> I have the following command which performs a find on the current
> directory
> and works perfectly:
>
> FILE_COUNT=$( eval 'find . -maxdepth 1' "${OPT}" |wc -l |sed 's/^[ ]
> *//' )
>
> However, I now want to modify that command to work not just on the
> current directory
> but to a variable. However, because the dot (. (the current dir)) is
> single quoted,
> it failed when I tried:
>
> FILE_COUNT=$( eval 'find' "$FOLDER" '-maxdepth 1' "${OPT}" |wc -l |sed
> 's/^[ ]*//' )

FILE_COUNT=$(
eval 'find "$FOLDER///." -maxdepth 1' "${OPT}" | grep -c ///
)

>
> I thought that I could get away with this, I guess, because "${OPT}"
> is double quoted
> and works (as in the first variable assignment).
>
> Is it possible to fix this in the way I'm trying to do? How should I
> try it?
>
>
>
>


--
St�phane