[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] unset all elements but not the whole array
From: |
Peng Yu |
Subject: |
[Help-bash] unset all elements but not the whole array |
Date: |
Mon, 5 Aug 2019 22:23:11 -0500 |
Hi,
I don't see an easy way to unset all elements but not the whole array.
In the following example, I still want the variable x be accessible.
Is it possible with one command? Thanks.
$ declare -a x=(a b c)
$ unset x
$ declare -p x
-bash: declare: x: not found
$ help unset
unset: unset [-f] [-v] [-n] [name ...]
Unset values and attributes of shell variables and functions.
For each NAME, remove the corresponding variable or function.
Options:
-f treat each NAME as a shell function
-v treat each NAME as a shell variable
-n treat each NAME as a name reference and unset the variable itself
rather than the variable it references
Without options, unset first tries to unset a variable, and if that fails,
tries to unset a function.
Some variables cannot be unset; also see `readonly'.
Exit Status:
Returns success unless an invalid option is given or a NAME is read-only.
--
Regards,
Peng
- [Help-bash] unset all elements but not the whole array,
Peng Yu <=