Re: Problem with list of aliases

2017-03-14 Thread Chet Ramey
On 3/14/17 12:56 PM, Pedro Gimeno wrote:
> When using the 'alias' command without parameters, or with the '-p' 
> parameter, a list of aliases is displayed. This list has the form:
> 
>   alias name='value'
> 
> 'help alias' states that this form is 'reusable', thus implying, if I 
> understand it correctly, that it can be fed back to bash.
> 
> But that's not always the case. I have an alias called '-' that resolves to 
> 'cd -'. This alias needs to be entered as follows:
> 
>   alias -- -='cd -'
> 
> However, it is output by the 'alias' command as:
> 
>   alias -='cd -'

This was changed in bash-4.4.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Problem with list of aliases

2017-03-14 Thread Pedro Gimeno
When using the 'alias' command without parameters, or with the '-p' parameter, 
a list of aliases is displayed. This list has the form:

  alias name='value'

'help alias' states that this form is 'reusable', thus implying, if I 
understand it correctly, that it can be fed back to bash.

But that's not always the case. I have an alias called '-' that resolves to 'cd 
-'. This alias needs to be entered as follows:

  alias -- -='cd -'

However, it is output by the 'alias' command as:

  alias -='cd -'

And when that line is input to bash, it produces an error:

  bash: alias: -=: invalid option
  alias: usage: alias [-p] [name[=value] ... ]

This can be easily fixed with sed to ensure the output is compatible with bash:

  alias -p | sed 's/^alias -/alias -- -/'

Therefore, either the docs need to be fixed (by adding a caveat, perhaps 
suggesting the 'sed' workaround, or by omitting 'reusable'), or the output of 
'alias -p' should include '--' when the alias name starts with '-'.