Ask Sawal

Discussion Forum
Notification Icon1
Write Answer Icon
Add Question Icon

Jha ookfxolx Areebah




Posted Answers



Answer


On computers, variables are used in a similar way.

For instance, any person with a user account on a computer has a home directory where the computer keeps their personal data. But each user has a distinct home directory (/home/seth for Seth, /home/tux for Tux, and so on for each user), so when you want to refer generically to a home directory, you could use the variable $HOME to indicate the home directory of the current user, regardless of the user's login name.

Environment variables are special variables (like $HOME) that contain information about your login session. They're stored for the system shell to use when executing commands. They exist whether you’re using Linux, Mac, or Windows. Many of these variables are set by default during installation or user creation.

While environment variables apply to all modern systems, this article specifically addresses environment variables in the Bash shell on Linux, BSD, Mac, and Cygwin.

Environment variables are no different, technically, than variables. They can be set, recalled, and cleared with exactly the same syntax used for variables. If you’re not used to using variables in Bash, read my variables in Bash article before continuing.

You don’t often use environment variables directly. They’re referenced by individual applications and daemons as needed. For instance, your home directory is set as an environment variable when you log in. For example, on Linux you can see your HOME environment variable's contents like this:

On a Mac:

On Windows:

You can view all environment variables set on your system with the env command. The list is long, so pipe the output through more to make it easier to read:

Environment variables can be useful when you want to override default settings, or when you need to manage new settings that your system has no reason to create on its own. For instance, when you type a command, the only reason your computer knows how to find the application corresponding to that command is that the PATH environment variable tells it where to look. This variable lists valid directories for your operating system to search for commands, whether that command is ls or cp, or a graphical application like Firefox or Lutris, or anything else.

Different environment variables get used by different systems. Your PATH variable is vital to your terminal emulator, for instance, but a lot less significant to, say, Java (which has its own paths, which point to important Java libraries). However, the USER variable is used by several systems as a way to identify who is requesting a service. For example, if you’re on a multiuser system and need to check your local mailbox, your mail command knows which mail spool to retrieve based on the MAIL and USER variables.

Usually, the installer program, whether it’s dnf on Fedora, apt on Ubuntu, brew on Mac, or a custom installer, updates your environment variables for a new application. Sometimes, though, when you’re installing something outside of your distribution’s intended toolset, you may have to manage an environment variable yourself. Or you might choose to add an environment variable to suit your preferences. If you decide you want to keep some applications in a bin folder located in your home directory, then you must add that directory to your PATH so your operating system knows to look there for applications to run when you issue a command.

You can add a location to your path the way you create throw-away variables. It works, but only as long as the shell you used to modify your system path remains open. For instance, open a Bash shell and modify your system path:

Confirm the result:

Close the session:

Open a new one and take a look at the PATH variable:

This variable has reverted to its default state because PATH isn’t getting set with each new shell. For that, you must configure your variables to load any time a shell is launched.

You can set your own persistent environment variables in your shell configuration file, the most common of which is ~/.bashrc. If you’re a system administrator managing several users, you can also set environment variables in a script placed in the /etc/profile.d directory.

The syntax for setting a variable by configuration file is the same as setting a variable in your shell:

Close the current shell, or else force it to load the updated config:

Finally, take another look at your system path:

It is now set correctly to include your additional custom directory.

You can create and manipulate environment variables at will, and some applications do just that. This fact means that many of your environment variables aren’t used by most of your applications, and if you add your own arbitrary variables then some could be used by nothing at all. So the question is: How do you find out which environment variables are meaningful?

The answer lies in an application’s documentation. For instance, to find out what options are available to you for your general Bash environment, you can read the Bash documentation. While the Bash man page mentions many important variables, the GNU info page for Bash features two exhaustive lists of useful Bourne Shell and Bash environment variables, and how each is used.

For example, in the info page list:

This output tells you that the HISTCONTROL environment variable controls how your Bash history is presented, and what values you can use to customize that experience. In this example, the ignoredups value tells the output of the history command to ignore duplicate lines.

You can test this one easily. First, issue the same command twice in a row:

View your history, or at least the most recent entries:

You can see that duplicate entries are indeed listed now.

Set a new environment variable in your .bashrc file based on what you read in the info page:

Save and then load your new configuration:

Issue two commands twice in a row:


Answer is posted for the following question.

Bash where to set environment variables?

Answer


Stretching the muscles around the joints may help with the symptoms.

A study published in Health Technology Assessment found that simple stretching and strengthening exercises can help alleviate the symptoms of RA.

Stretching can support traditional methods of care, concluded the authors.

Before attempting a stretch on an area with RA, you should consult with a doctor or physical therapist. Some exercises can add stress to the joints.

Some less-effort forms of exercise may benefit people with RA.

Swimming or cycling can strengthen the muscles around the joints.

This can help reduce the impact on the joints.

There is conflicting medical evidence on the benefits of applying heat or cold to relieve joint pain.

Some people find relief by putting heat and cold on the sore areas. Anyone can apply heat or ice packs at home.

Never put ice on the skin.

Wrap it in a towel.


Answer is posted for the following question.

How to relieve rheumatoid arthritis?

Answer


  • Create a folder for the samples you plan to use.
  • Drag the sample(s) you want to use into the folder.
  • Open a text editor such as Notepad (the simpler the better — you don't need formatting adding extraneous characters to the underlying text file).

Answer is posted for the following question.

How to make sfz files?


Wait...