[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: semicolon at beginning of line
From: |
Maarten Billemont |
Subject: |
Re: semicolon at beginning of line |
Date: |
Tue, 10 Apr 2012 09:22:16 +0200 |
On 10 Apr 2012, at 06:03, Elliott Forney wrote:
> Here is another example that appears to defy my expectations. In this
> case, the semicolon is allowed:
>
> sine:~$ hello='echo hello'
> sine:~$ world='echo world'
> sine:~$ ${hello};${world}
> hello
> world
> sine:~$ unset hello
> sine:~$ ${hello};${world}
> world
> sine:~$ unset world
> sine:~$ ${hello};${world}
Those are not empty statements. It's important to understand the difference
between:
$var
and:
eval "$var"
People should stop trying to execute code by parameter expansion, and
specifically stop thinking that parameter-expanded words are evaluated as bash
code.
>
> Thanks!
> Elliott Forney
>
> On Mon, Apr 9, 2012 at 10:02 PM, Elliott Forney
> <elliott.forney@gmail.com> wrote:
>> Sure, a comment can be used to place a line in your history but that
>> doesn't really address the examples I had. Just seems to me like a
>> lone semicolon could be treated as a newline/noop. I can't seem to
>> think of anything that this would break but, of course, that doesn't
>> mean it wouldn't. The end of a case in a switch statement is
>> certainly an interesting one, hadn't thought of that, but it should be
>> possible to handle that by checking for ;; as a token before ;.
OK, so you're saying, let's change bash so that an empty statement becomes a
noop statement. Except for when that empty statement is preceded by a
semicolon and happens to have no whitespace, because then it could be a case
delimiter.
Frankly, what are you hoping to gain from this? This will just introduce new
rules with new exceptions and inconsistencies. If it were possible to do a
blanket rule: empty statements before a semicolon are noops, I might be OK with
it, but if it requires adding additional addendums to the rule, "oh wait,
except for this and that case", my vote is out.
>>
>> I might mention that ksh, zsh and tcsh all allow lines to begin with a
>> semicolon. zsh even allows "; ; ; echo hello world ; ; ;" although
>> ksh only allows a single ; at the beginning of a line.
>>
>> On Sun, Apr 8, 2012 at 6:48 PM, Joseph Fredette <jfredett@gmail.com> wrote:
>>> Could also use a #, no?
>>>
>>> On Sun, Apr 8, 2012 at 8:46 PM, Steven W. Orr <steveo@syslang.net> wrote:
>>>
>>>> On 4/7/2012 4:00 PM, Elliott Forney wrote:
>>>>
>>>>> I wish bash would happily execute lines that begin with a semicolon,
>>>>> i.e., treat it as a no-op followed by a command. The following
>>>>> examples come to mind:
>>>>>
>>>>> $ infloop& echo hello
>>>>> [2] 11361
>>>>> hello
>>>>> $ infloop&; echo hello
>>>>> bash: syntax error near unexpected token `;'
>>>>>
>>>>> $ echo hello; echo world
>>>>> hello
>>>>> world
>>>>> $ echo hello;; echo world
>>>>> bash: syntax error near unexpected token `;;'
>>>>>
>>>>> $ ; echo hello world
>>>>> bash: syntax error near unexpected token `;'
>>>>>
>>>>> Any thoughts?
>>>>>
>>>>> Thanks,
>>>>> Elliott Forney
>>>>>
>>>>
>>>> Just use a colon.
>>>>
>>>> : echo Hello world.
>>>>
>>>> I use it all the time to 'park' a command in my history. Then when I'm
>>>> ready, I just back up to it and remove the colon.
>>>>
>>>>
>>>> --
>>>> Time flies like the wind. Fruit flies like a banana. Stranger things have
>>>> .0.
>>>> happened but none stranger than this. Does your driver's license say Organ
>>>> ..0
>>>> Donor?Black holes are where God divided by zero. Listen to me! We are all-
>>>> 000
>>>> individuals! What if this weren't a hypothetical question?
>>>> steveo at syslang.net
>>>>
>>>>
>
smime.p7s
Description: S/MIME cryptographic signature