Linux/Unix: Bash Set Shell Variable Command

Linux/Unix: Bash Set Shell Variable Command

To set a shell variable in Bash on Linux or Unix, you can use the export command. The export command allows you to define and assign values to shell variables, which can be used to store and access information in your shell scripts and commands.

To set a shell variable using the export command, you can use the following syntax:

refer to‮ruttual:‬i.com
export VARNAME=value

This will set the VARNAME variable to the value specified. You can then reference the VARNAME variable in your shell scripts and commands using the $ character, followed by the variable name. For example, if you set the VARNAME variable to hello, you can reference it in your shell scripts and commands using $VARNAME or ${VARNAME}.

To make the changes to the shell variables persistent across terminal sessions, you can add the export command to your shell's configuration file. The location and name of the configuration file depends on the shell that you are using. For example, if you are using the Bash shell, you can add the export command to the ~/.bashrc file.

By using the export command, you can easily set shell variables in Bash on Linux or Unix. This can be useful for storing and accessing information in your shell scripts and commands.

Created Time:2017-10-16 14:38:53  Author:lautturi