[Top][All Lists]

[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: Gecko/20090812 Thunderbird/ Mnenhy/

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
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/


reply via email to

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