tech-userlevel archive

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

Re: Fwd: Re: interactive shell detection in shrc



    Date:        Sun, 29 Sep 2024 23:59:48 +0000 (UTC)
    From:        RVP <rvp%SDF.ORG@localhost>
    Message-ID:  <cea12c78-54d6-dbfc-84bd-f1674ecfef4f%SDF.ORG@localhost>


  | This is _very_ surprising; esp. when /bin/sh doesn't allow chars.
  | like `/' and `.' in the function name.

Huh?

sh $ a.v() echo I have a dot in my name
sh $ a.v
I have a dot in my name

You can even define:
sh $ .() echo My name is dot, but I can never be called

but as that suggests doing do is a waste of time, as there is
a special builtin '.' and those are always sought before functions.

But:
sh $ ..() echo dots everywhere
sh $ ..
dots everywhere

You're right about '/' though, as the command search rules
preclude ever finding a function whose name contains a '/'
hence defining one is certain to be futile (unlike with '.').
(And no, quoting it wouldn't help, quotes are removed before
command searching happens.)

But / (plus \0 which can't even be entered) is the only character
prohibited, though for some (like $) the name needs to be quoted
to work (that's just because of the nature of the parser, and could
be fixed, possibly, but isn't really worth it - in all these cases
the name would need to be quoted to call it anyway, to avoid
expansions happening - which never happen to a function name in
the definition).

sh $ \ () echo I am a space
sh $ ' '
I am a space
sh $ \  
I am a space

(the 2nd of those commands has a space after the \ which might, or
might not, survive the e-mail transport and various MUAs).


  | Can't see a use for this--except to suppress an error message 
  | $ ''() false
  | [...]
  | $ unset foo
  | $ if "$foo"; then echo set; else echo unset; fi

Yes, that's the context in which this (mostly nonsense) diversion arose.

  | or, to create (mildly) obfuscated fork-bombs:

That can be done with any name, it would be more likely to
be productive using something like "ls" that a user is likely
to type, unlike '' as a command name.

But in general, no, there's probably not a lot of use for it, but
nor is there any particular reason to add special case code to
prohibit it.

kre



Home | Main Index | Thread Index | Old Index