Creating and setting variables within a script (or shell prompt) is fairly simple. The syntax is:
varName=someValue export varName export vech="Bus" echo "$vech"
How do I unset a variable in bash?
Use unset command to delete the variables during program execution. It can remove both functions and shell variables. The syntax is:
unset varName
To unset the $vech, enter:
unset vech
Verify it:
echo $vech
A note about readonly variables
Please note that some variables cannot be unset if they are defined as readonly by the system or sysadmin:
unset BACKUPDIR
Sample outputs:
-bash: unset: BACKUPDIR: cannot unset: readonly variable
You can define your readonly variables using the following syntax:
declare -r BACKUPDIR="foo"
How do I unset a shell function on bash?
The syntax is as follows to treat each varName as a shell function:
unset -f varName unset -f tarhelper
For more info, type:
$ help unset
$ help declare
$ man bash
🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 3 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
How is the picture(“How to I unset a variable in Bash?”) created? Which tool do you use?
Gimp
for i in { 1..7 }
do
echo “welcome $i”
done
does not work well….what can i do???