How to unset all variables in shell?

can I use unset to unset all the variables in a shell sciprt?

VAR1=1
VAR2=2
VAR3=3
unset

whether this unset will afftect any system variables?

Thanks,

The unset command deletes a shell variable,or non-shell variable effectively setting it to null. Note that this command
does not affect positional parameters

but note that you need to put the variable name after the unset command.

Example1:-
unset PATH
echo $PATH

Example2:-
variable=hello # Initialized.
echo "variable = $variable"
unset variable # Unset.
# Same effect as: variable=
echo "(unset) variable = $variable" # $variable is null.

BR

The following function 'gsunset', deletes the variables specified by an RE :

gunset()
{
  local var_re="${1:-.*}"
  eval $( set | \
         awk -v FS='='        \
             -v VAR="$var_re" \
            '$1 ~ VAR { print "unset", $1 }' )
}

VAR1=value1
VAR2=value2
VAR3=value3

echo "Vars before gunset"
set | grep ^VAR
gunset 'VAR.*'
echo "Vars after gunset"
set | grep ^VAR

Output

Vars before gunset
VAR1=value1
VAR2=value2
VAR3=value3
Vars after gunset

Jean-Pierre.

Change your approach. NEVER use undeclared variables. There is an option "set -o nounset" if I remember correctly.
You should have something like this:

#!/bin/env ksh
typeset my_variable
typeset all_my_variables_should_be_defined_like_that
my_variable='abc'