What the heck is this in my ~

Brandon S Allbery KF8NH allbery at kf8nh.com
Sat Jul 10 22:31:19 PDT 2010


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

On 7/11/10 01:14 , Scott Haneda wrote:
> Ahh, ok, I get it now.  Its the ">" that is the command.  That was where I was hung up. I generally should be able to paste pretty much anything into the shell; unless it leads with touch, rm, cat, whatever, it won't do much.
> 
> But > is a command of sorts, and I should have known that, I use it all the time.
> 
> Rather than:
>     `echo "" > somefile.txt`
> To clear it out...
> I will just do:
>     `>somefile.txt`

More to the point, redirections can occur anywhere on a command line that
isn't quoted.  If there's no actual command, most shells will pretend the
command is ":" (a no-op that, ages and ages ago, was the comment character);
beware that zsh can decide that the default command is "cat", though.  (See
the zsh manual/info documents.)

So in this case the shell somehow got fed those "---> Computing dependencies
for ..." lines (usually a paste mishap):  first it evaluates the redirection
"> Configuring", leaving the "command" "--- dependencies for ..."; then it
tries to run the "command" and discovers that "---" doesn't exist, but by
then the redirection has already occurred and you now have an empty file
"Configuring".

(You may want to turn on the shell's no-clobber mode, so mistakes like this
can't wipe out files you care about.  It's "set -o noclobber" in bash and
"setopt noclobber" in zsh.)

(Pedantic detail:  the reason the shell doesn't catch the missing program
before doing the redirection is that it's prone to race conditions if you do
it beforehand, and somewhat complex to boot because it could be an alias, a
function, an autoloaded function (see the info pages), etc.  It *would* be
possible to alter this so that it could be delayed right up to the final
exec(), but the bash and zsh developers (not to mention ash/dash, etc.) have
often learned the hard way that changes of this sort introduce behavioral
corner cases that break existing scripts.  Granted, very few of the people
here are likely to have abused the shell enough to trip over those corners :)

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      allbery at kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university      KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkw5VycACgkQIn7hlCsL25W/wwCgmrAPttPQHWrgENo7pZRZ2Fl+
Nm8AnioH3QEEenKRFn+RAiuUs9K2N4df
=rdqo
-----END PGP SIGNATURE-----


More information about the macports-users mailing list