bug-bash
[Top][All Lists]
Advanced

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

Re: No tilde expansion right after a quotation


From: Jon Seymour
Subject: Re: No tilde expansion right after a quotation
Date: Mon, 16 Feb 2009 10:10:24 +1100

If you are willing to trade conciseness in order to eliminate use of
builtin commands, you can use.

  local tmp=~usr1/blah/blah
  CPATH="${CPATH}${CPATH:+:}${tmp}"

However, if you are concerned about echo failing, then you also need
to be concerned about local failing.

Hence:

  local tmp=~usr1/blah/bah
  [ $? -eq 0 ] || ... do something
  CPATH="${CPATH}${CPATH:+:}${tmp}"

However, that is taking defensive programming to absurd levels.

If the builtin echo fails it will be because the bash interpreter has
suffered a catastrophic failure of some kind [ e.g. run out of memory
]. Once that has happened, all bets are off anyway.

To be honest, it seems to me that your reluctance to use $(echo
~usr1/blah/blah) is rooted in an aesthetic objection or perhaps a lack
of familiarity with the command substitution idiom. If the latter, I'd
encourage you to reconsider, since command substitution is one of
bash's most powerful features.

[ Of course, others more experienced with bash idioms may object to
$(echo ~usr1/blah/blah)  on aesthetic grounds too - I welcome any
suggested improvement!. ]

jon.

On Mon, Feb 16, 2009 at 9:54 AM, Angel Tsankov <fn42551@fmi.uni-sofia.bg> wrote:
> Jon Seymour wrote:
>> On Mon, Feb 16, 2009 at 9:26 AM, Angel Tsankov
>> <fn42551@fmi.uni-sofia.bg> wrote:
>>> Jon Seymour wrote:
>>>> There may be other ways to do this, but:
>>>>
>>>>     CPATH="${CPATH}${CPATH:+:}$(echo ~usr1/blah/blah)"
>>>>
>>>> should work.
>>>
>>> Well, I'd like to avoid the use of external commands.
>>>
>>
>> echo is a builtin, so if you are worried about performance costs
>> associated with its execution, you shouldn't be.
>
> In fact, I'm more concerned that in the expression:
>
> CPATH="${CPATH}${CPATH:+:}$(echo ~usr1/blah/blah)" some-command
>
> I have no way to check echo's exit status.  While it is probably true that
> echo will hardly ever fail, I just want to make sure my script works as I
> expect it to.  This means handling every possible error.
>
> -Angel
>
>
>
>
>
>




reply via email to

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