help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Assigning builtins behavior


From: Quentin L'Hours
Subject: Re: [Help-bash] Assigning builtins behavior
Date: Sun, 7 Jan 2018 18:54:13 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

On 2018-01-07 06:31 PM, Andy Chu wrote:
FWIW, here is another case where the shell parser has knowledge of the '=' character in assignments.  It's not just an opaque string to a builtin (e.g. as in 'env').

$ echo x-~andy
x-~andy

$ echo x=~andy
x=/home/andy

So although no assignments are made, merely changing the - character to = causes tilde expansion to be triggered.

Dash has the opposite behavior, which IMO is very annoying and inconsistent:

x=~andy  # YES tilde expansion in dash
readonly x=~andy  # NO tilde expansion in dash

This is pretty interesting, I totally understand that you would want the same behavior when adding a simple command on the left, I mean this would be pretty confusing to have different outputs like dash does.

However I find it also really confusing that = has such power, meaning if you always think your command args should split when they contain an IFS character before field splitting then the result is quite unexpected. I guess that's why I find the result of dash more logic.

But bash way of treating the = sign seems indeed safer and honestly the a=$(echo 1 b=2) splitting is pretty unlikely to be a behavior you'd want in a script.

--
Quentin



reply via email to

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