[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Assigning builtins behavior
From: |
Quentin L'Hours |
Subject: |
[Help-bash] Assigning builtins behavior |
Date: |
Sun, 7 Jan 2018 13:10:57 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 |
Hi,
I've always thought builtins could not have a custom parsing, however it
seems that export/readonly/declare/local (all the builtins creating an
assignment) are able to disable field splitting when an assignment takes
place, why is that? I know a simple assignment disables field splitting,
but after all that's because the grammar states it should, but doesn't
POSIX requires all simple commands to have the same splitting behavior?
bash$ foo=$(echo 1 bar=2)
bash$ echo "$foo"
1 b=2
This is logic, simple assignment doesn't triggers field splitting,
that's the rule.
bash$ set a=$foo
bash$ echo "$1"
a=1
This is logic too, field splitting happens as expected
bash$ readonly a=$foo
bash$ echo "$a"
1 b=2
Why? I know simple assignment doesn't split but I would have thought
this should still follow the simple commands arguments expansion and
thus should do 2 assignments. I mean builtins shouldn't be able to have
their custom parsing, if they do then they should be classified as
keywords (like [[ ]]). What should be the POSIX way of doing things? Is
this a bash extension?
As a side note ksh has the same behavior, but dash follows what I
thought would be the "normal" behavior:
dash$ foo=$(echo 1 b=2)
dash$ readonly a=$foo
dash$ echo "$a"
1
dash$ echo "$b"
2
Thanks,
--
Quentin
- [Help-bash] Assigning builtins behavior,
Quentin L'Hours <=