bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to conditionally search?


From: Eric Blake
Subject: Re: How to conditionally search?
Date: Sat, 28 Nov 2009 12:01:05 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Peng Yu on 11/28/2009 9:18 AM:
>> If find is considering the file /tmp/a/foo.sh, it runs this shell command...
>>
>> test ! -f "${1%.sh}.py"'
>>
>> with $1 set to /tmp/a/foo.sh.    To see that work, type this:
>>
>> set /tmp/a/foo.sh
>> test ! -f "${1%.sh}.py"'
>> echo $?
> 
> I know that {} takes the matched .sh file. I still don't understand
> how the second 'sh' before '{}' work. Would you please let me know?

'man bash'

/bin/sh (or any other decent shell, like bash, dash, zsh), when invoked
with the arguments "-c script name arg1 arg2 ...", runs script with $0 set
to name, and $1 set to arg1.  We don't really care about $0 in this case,
but must stick something there (sh, in the above example) so we can get to
the arg1 slot that we care about.  And we MUST use the arg1 slot, rather
than using {} inside script, to properly account for quoting issues
(consider if the name contains a ').

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksRc3EACgkQ84KuGfSFAYDQnwCaAzuOPyT01FHhMrgS2v5Qga0C
8/EAnil+4XgtmbOTn3TfdLsD5wnCzwnY
=8oB3
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]