Negative array subscript with unset
I all versions I have tried, unsetting an array element using a negative index fails: $ array=( q w e r t y ) $ unset 'array[-1]' bash: [-1]: bad array subscript -- Chris F.A. Johnson, http://cfajohnson.com/ Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Re: Negative array subscript with unset
On Sat, Mar 12, 2011 at 6:21 PM, Chris F.A. Johnson ch...@cfajohnson.com wrote: I all versions I have tried, unsetting an array element using a negative index fails: $ array=( q w e r t y ) $ unset 'array[-1]' bash: [-1]: bad array subscript -- Chris F.A. Johnson, http://cfajohnson.com/ Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Assignments to negative indices don't work either. (Bash 4.2) -- Visit serverfault.com to get your system administration questions answered.
Re: Negative array subscript with unset
On 3/12/11 7:21 PM, Chris F.A. Johnson wrote: I all versions I have tried, unsetting an array element using a negative index fails: $ array=( q w e r t y ) $ unset 'array[-1]' bash: [-1]: bad array subscript Negative subscripts only work with ${parameter[subscript]}. The problem is that I put the text in the manual page describing their use in the wrong place. It should have gone in the paragraph describing array references. Negative subscripts will work in more contexts in the next version of bash. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/