help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] What is the different between `unset a[n-1]` in interact


From: konsolebox
Subject: Re: [Help-bash] What is the different between `unset a[n-1]` in interactive mode and non-interactive mode?
Date: Wed, 19 Dec 2018 01:30:53 +0800

On Tue, Dec 18, 2018 at 9:56 AM Peng Yu <address@hidden> wrote:
>
> 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
>

https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html

And use failglob.

-- 
konsolebox



reply via email to

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