Re: [CentOS] stupid bash question

2012-08-16 Thread Craig White

On Aug 16, 2012, at 3:14 PM, Kahlil Hodgson wrote:

> On 16/08/12 08:19, Craig White wrote:
>> the relevant snippet is...
>> 
>> NAME="*.mov" cd $IN if test -n "$(find . -maxdepth 1 -name $NAME
>> -print -quit)"
>> 
> The problem is the outermost double quotes in the "$(...)" expression
> and figuring out how to pass the appropriate quotes into the subshell 
> created by the $(). One trick is to let the outer shell do the 
> interpolation first.
> 
> The following script may be informative:
> 
> ==
> #!/bin/bash
> 
> NAME="*.mov"
> echo $NAME
> echo "$NAME"
> 
> echo $(echo $NAME)
> echo $(echo "$NAME")
> echo $(echo \"$NAME\")
> echo $(echo '$NAME')
> 
> echo "$(echo $NAME)"
> echo "$(echo "$NAME")"
> echo "$(echo \"$NAME\")"
> echo "$(echo '$NAME')"
> 
> if test -n "$(find . -name "$NAME")"
> then
> echo FOUND IT
> fi
> ==
> 
> Hope this helps,

sort of but the other suggestion was more than sufficient for my purposes.

Interesting that I could have the variable in double quotes inside the double 
quoted braces and it still worked. I would have never actually tried it.

Thanks

Craig
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-16 Thread Kahlil Hodgson
On 16/08/12 08:19, Craig White wrote:
> the relevant snippet is...
>
> NAME="*.mov" cd $IN if test -n "$(find . -maxdepth 1 -name $NAME
> -print -quit)"
>
The problem is the outermost double quotes in the "$(...)" expression
and figuring out how to pass the appropriate quotes into the subshell 
created by the $(). One trick is to let the outer shell do the 
interpolation first.

The following script may be informative:

==
#!/bin/bash

NAME="*.mov"
echo $NAME
echo "$NAME"

echo $(echo $NAME)
echo $(echo "$NAME")
echo $(echo \"$NAME\")
echo $(echo '$NAME')

echo "$(echo $NAME)"
echo "$(echo "$NAME")"
echo "$(echo \"$NAME\")"
echo "$(echo '$NAME')"

if test -n "$(find . -name "$NAME")"
then
 echo FOUND IT
fi
==

Hope this helps,

Kal
-- 
Kahlil (Kal) Hodgson   GPG: C9A02289
Head of Technology (m) +61 (0) 4 2573 0382
DealMax Pty Ltd(w) +61 (0) 3 9008 5281

Suite 1415
401 Docklands Drive
Docklands VIC 3008 Australia

"All parts should go together without forcing.  You must remember that
the parts you are reassembling were disassembled by you.  Therefore,
if you can't get them together again, there must be a reason.  By all
means, do not use a hammer."  -- IBM maintenance manual, 1925

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-16 Thread Craig White

On Aug 15, 2012, at 5:11 PM, fred smith wrote:

> how about something (seemingly simple) like this:
> 
> find out how many there are:
> 
>   count=`ls * | grep -c .MOV$`
> 
> then diagnose the result:
> 
>   if [ $count -ge 1 ]
>   then
>   do your stuff here
>   else
>   echo oops. nothing to do!
>   fi
> 
> of course, there are pitfalls... we're asuming that there are only FILES
> that would match the pattern ".MOV", no directories.

very effective for my purposes, thanks.

Craig
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-15 Thread Mark LaPierre
On 08/15/2012 06:19 PM, Craig White wrote:
> the relevant snippet is...
>
> NAME="*.mov"
> cd $IN
> if test -n "$(find . -maxdepth 1 -name $NAME -print -quit)"
>
> and if there is one file in this directory - ie test.mov, this works fine
>
> but if there are two (or more) files in this directory - test.mov, test2.mov
>
> then I get an error...
> find: paths must precede expression
>
> So my code is evidently wrong. I just want a test for 1 or more files ending 
> in .mov in the directory?
>
> Any one want to toss me a bone here?
>

Are you trying to find out if there are one or more files that match, or 
are you trying to list the name(s) of the files?

NAME=`ls *.mov`

for FILE in $NAME
do
echo "$FILE"
done


-- 
 _
°v°
   /(_)\
^ ^  Mark LaPierre
Registerd Linux user No #267004
www.counter.li.org

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-15 Thread fred smith
On Wed, Aug 15, 2012 at 05:19:22PM -0600, Larry Martell wrote:
> On Wed, Aug 15, 2012 at 5:08 PM, Craig White  wrote:
> > Some really good suggestions but unfortunately no dice
> >
> > On Aug 15, 2012, at 3:22 PM, Larry Martell wrote:
> >
> >> Run the script with -x to see what's happening. $NAME is probably
> >> getting expanded. You might have to set noglob.
> > 
> > set +o noglob (inside or outside script made no difference
> 
> This worked for me:
> 
> $ cat t.sh
> set -o noglob
> NAME="*.mov"
> find . -maxdepth 1 -name $NAME -print
> 
> $ touch t.mov t2.mov
> $ bash t.sh
> ./t.mov
> ./t2.mov


how about something (seemingly simple) like this:

find out how many there are:

count=`ls * | grep -c .MOV$`

then diagnose the result:

if [ $count -ge 1 ]
then
do your stuff here
else
echo oops. nothing to do!
fi

of course, there are pitfalls... we're asuming that there are only FILES
that would match the pattern ".MOV", no directories.

-- 
 Fred Smith -- fre...@fcshome.stoneham.ma.us -
The Lord detests the way of the wicked 
  but he loves those who pursue righteousness.
- Proverbs 15:9 (niv) -
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-15 Thread Larry Martell
On Wed, Aug 15, 2012 at 5:08 PM, Craig White  wrote:
> Some really good suggestions but unfortunately no dice
>
> On Aug 15, 2012, at 3:22 PM, Larry Martell wrote:
>
>> Run the script with -x to see what's happening. $NAME is probably
>> getting expanded. You might have to set noglob.
> 
> set +o noglob (inside or outside script made no difference

This worked for me:

$ cat t.sh
set -o noglob
NAME="*.mov"
find . -maxdepth 1 -name $NAME -print

$ touch t.mov t2.mov
$ bash t.sh
./t.mov
./t2.mov
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-15 Thread Craig White
Some really good suggestions but unfortunately no dice

On Aug 15, 2012, at 3:22 PM, Larry Martell wrote:

> Run the script with -x to see what's happening. $NAME is probably
> getting expanded. You might have to set noglob.

set +o noglob (inside or outside script made no difference

On Aug 15, 2012, at 3:45 PM, Steve Thompson wrote:

> The substitution of $NAME is expanding the wild card, giving you a single 
> -name with two arguments. You probably want something like:
> 
>   NAME="\*.mov"

-
Definitely agree that it's expanding the glob but this doesn't work
-
On Aug 15, 2012, at 3:51 PM, Jérémie Dubois-Lacoste wrote:  (and Patrick Welch 
too)

> I gess you could also avoid the expension with:
> if test -n "$(find . -maxdepth 1 -name \"$NAME\" -print -quit)"

thought this would be a winner but it seems to completely miss everything with 
the $NAME completely

Thanks

Craig
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-15 Thread Patrick Welch
Put escaped double quotes around name, like \"$NAME\" in the test expression. 
-- 
Pat Welch
Sent from my Android phone with K-9 Mail.

Craig White  wrote:

the relevant snippet is...

NAME="*.mov"
cd $IN
if test -n "$(find . -maxdepth 1 -name $NAME -print -quit)"

and if there is one file in this directory - ie test.mov, this works fine

but if there are two (or more) files in this directory - test.mov, test2.mov

then I get an error...
find: paths must precede expression

So my code is evidently wrong. I just want a test for 1 or more files ending in 
.mov in the directory?

Any one want to toss me a bone here?

-- 
Craig White ~ craig.wh...@ttiltd.com
1.800.869.6908 ~~ www.ttiassessments.com 

Need help communicating between generations at work to achieve your desired 
success? Let us help!

_

CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-15 Thread Jérémie Dubois-Lacoste
I gess you could also avoid the expension with:
if test -n "$(find . -maxdepth 1 -name \"$NAME\" -print -quit)"

2012/8/15 Steve Thompson :
> On Wed, 15 Aug 2012, Craig White wrote:
>
>> the relevant snippet is...
>>
>> NAME="*.mov"
>> cd $IN
>> if test -n "$(find . -maxdepth 1 -name $NAME -print -quit)"
>>
>> and if there is one file in this directory - ie test.mov, this works fine
>>
>> but if there are two (or more) files in this directory - test.mov, test2.mov
>>
>> then I get an error...
>> find: paths must precede expression
>
> The substitution of $NAME is expanding the wild card, giving you a single
> -name with two arguments. You probably want something like:
>
> NAME="\*.mov"
>
> Steve
> ___
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-15 Thread Steve Thompson
On Wed, 15 Aug 2012, Craig White wrote:

> the relevant snippet is...
>
> NAME="*.mov"
> cd $IN
> if test -n "$(find . -maxdepth 1 -name $NAME -print -quit)"
>
> and if there is one file in this directory - ie test.mov, this works fine
>
> but if there are two (or more) files in this directory - test.mov, test2.mov
>
> then I get an error...
> find: paths must precede expression

The substitution of $NAME is expanding the wild card, giving you a single 
-name with two arguments. You probably want something like:

NAME="\*.mov"

Steve
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] stupid bash question

2012-08-15 Thread Larry Martell
On Wed, Aug 15, 2012 at 4:19 PM, Craig White  wrote:
> the relevant snippet is...
>
> NAME="*.mov"
> cd $IN
> if test -n "$(find . -maxdepth 1 -name $NAME -print -quit)"
>
> and if there is one file in this directory - ie test.mov, this works fine
>
> but if there are two (or more) files in this directory - test.mov, test2.mov
>
> then I get an error...
> find: paths must precede expression
>
> So my code is evidently wrong. I just want a test for 1 or more files ending 
> in .mov in the directory?
>
> Any one want to toss me a bone here?

Run the script with -x to see what's happening. $NAME is probably
getting expanded. You might have to set noglob.
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos