[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] What is the different between `unset a[n-1]` in interactive
From: |
Peng Yu |
Subject: |
[Help-bash] What is the different between `unset a[n-1]` in interactive mode and non-interactive mode? |
Date: |
Mon, 17 Dec 2018 19:56:48 -0600 |
Hi,
I can remove an array element in the following script.
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
array=(a b c)
n=3
unset array[n-1]
declare -p array
$ ./main.sh
array=(a b c)
n=3
unset array[n-1]
declare -p array
declare -a array=([0]="a" [1]="b")
But when I run the same commands in the command line, it does not
delete the element.
$ array=(a b c)
$ n=3
$ unset array[n-1]
$ declare -p array
declare -a array=([0]="a" [1]="b" [2]="c")
However, if I quote it, then the element will be deleted.
$ unset 'array[n-1]'
$ declare -p array
declare -a array=([0]="a" [1]="b")
Why is there such a difference between the interactive mode and the
non-interactive mode? Thanks.
--
Regards,
Peng
- [Help-bash] What is the different between `unset a[n-1]` in interactive mode and non-interactive mode?,
Peng Yu <=