On 11/16/20 10:36 PM, Bodie wrote:
>
>
> On 17.11.2020 05:04, Jordan Geoghegan wrote:
>> Hello,
>>
>> I'm not sure if this is a bug, or if it's just a pdksh thing, but I
>> stumbled upon some interesting behaviour when I was tinkering around
>> with quoting and using a poor mans array:
>>
>> test=$(cat <<'__EOT'
>> # I'll choose not to close this quote
>> other_stuff
>> __EOT
>> )
>>
>> echo "$test"
>>
>>
>> When I run this command on ash, dash, yash, bash, zsh or ksh93 I get
>> the following output:
>>
>> # I'll choose not to close this quote
>> other_stuff
>>
>> But when I run it on ksh from base or any pdksh derivative it throws
>> an error about an unclosed quote:
>>
>> test.sh[8]: no closing quote
>>
>> This snippet works on every POSIX-y shell in the ports tree, and fails
>> on every pdksh variant I tried, including on NetBSD and DragonflyBSD
>> as well. I don't have the requisite esoteric knowledge regarding
>> pdksh's internal quoting logic, so I'm hoping one of the gurus here
>> can determine whether this is a bug or if I'm just doing something
>> annoying.
>>
>> Any insight that can be provided would be much appreciated.
>>
>
> What exactly are you trying to achieve?
>
> If you will look in sh(1) for 'Command expansion' then there are defined
> rules and your form is not between them.
>
> So error message about missing closing quote is actually proper behavior.
>
> Plus I will not be so sure that bash is behaving properly:
>
> $ bash -x test.sh
> ++ cat
> + test='
> # I'\''ll choose not to close this quote
> other_stuff'
> + echo '#' 'I'\''ll' choose not to close this quote other_stuff
> # I'll choose not to close this quote other_stuff
> $
>
> Notice how one single quote is here "test='" abd second one is in
> "other_stuff'"
>
> You can compare results between various shells with ktrace/ktruss too
>
> $ bash --version | head -1
> GNU bash, version 5.0.18(1)-release (x86_64-unknown-openbsd6.8)
> $
>
> If you want to read the file then you do not need interaction and if
> you want to get input from user then use 'read'
>
> As well it is good idea to avoid reserved words as a names for
> variables ;-)
> (test............)
>
>> Regards,
>>
>> Jordan
>
I'm not trying to achieve anything in particular, I was just testing out
differences in behaviour between different shells. I just noticed that
pdksh variants handled this differently than any other shell I tested in
the ports tree.
Regards,
Jordan
No comments:
Post a Comment