Fedora - Manage your shell environment - Printable Version +- Sick Gaming (https://www.sickgaming.net) +-- Forum: Computers (https://www.sickgaming.net/forum-86.html) +--- Forum: Linux, FreeBSD, and Unix types (https://www.sickgaming.net/forum-88.html) +--- Thread: Fedora - Manage your shell environment (/thread-91188.html) |
Fedora - Manage your shell environment - xSicKxBot - 07-05-2019 Manage your shell environment <div><p>Some time ago, the Fedora Magazine has published an <a href="https://fedoramagazine.org/set-zsh-fedora-system/">article introducing ZSH </a>— an alternative shell to Fedora’s default, bash. This time, we’re going to look into customizing it to use it in a more effective way. All of the concepts shown in this article also work in other shells such as bash.</p> <h3>Alias</h3> <p>Aliases are shortcuts for commands. This is useful for creating short commands for actions that are performed often, but require a long command that would take too much time to type. The syntax is:</p> <pre class="wp-block-preformatted">$ alias yourAlias='complex command with arguments'</pre> <p>They don’t always need to be used for shortening long commands. Important is that you use them for tasks that you do often. An example could be:</p> <pre class="wp-block-preformatted">$ alias dnfUpgrade='dnf -y upgrade'</pre> <p>That way, to do a system upgrade, I just type dnfUpgrade instead of the whole dnf command.</p> <p>The problem of setting aliases right in the console is that once the terminal session is closed, the alias would be lost. To set them permanently, resource files are used.</p> <h3>Resource Files</h3> <p>Resource files (or rc files) are configuration files that are loaded per user in the beginning of a session or a process (when a new terminal window is opened, or a new program like vim is started). In the case of ZSH, the resource file is <em>.zshrc</em>, and for bash it’s <em>.bashrc</em>.</p> <p>To make the aliases permanent, you can either put them in your resource. You can edit your resource file with a text editor of your choice. This example uses vim:</p> <pre class="wp-block-preformatted">$ vim $HOME/.zshrc</pre> <p>Or for bash:</p> <pre class="wp-block-preformatted">$ vim $HOME/.bashrc</pre> <p>Note that the location of the resource file is specified relatively to a home directory — and that’s where ZSH (or bash) are going to look for the file by default for each user.</p> <p>Other option is to put your configuration in any other file, and then source it:</p> <pre class="wp-block-preformatted">$ source /path/to/your/rc/file</pre> <p>Again, sourcing it right in your session will only apply it to the session, so to make it permanent, add the source command to your resource file. The advantage of having your source file in a different location is that you can source it any time. Or anywhere which is especially useful in shared environments.</p> <h3>Environment Variables</h3> <p>Environment variables are values assigned to a specific name which can be then called in scripts and commands. They start with the $ dollar sign. One of the most common is $HOME that references the home directory.</p> <p>As the name suggests, environment variables are a part of your environment. Set a variable using the following syntax:</p> <pre class="wp-block-preformatted">$ http_proxy="http://your.proxy"</pre> <p>And to make it an environment variable, export it with the following command:</p> <pre class="wp-block-preformatted">$ export $http_proxy</pre> <p>To see all the environment variables that are currently set, use the <em>env</em> command:</p> <pre class="wp-block-preformatted">$ env</pre> <p>The command outputs all the variables available in your session. To demonstrate how to use them in a command, try running the following echo commands:</p> <pre class="wp-block-preformatted">$ echo $PWD<br />/home/fedora<br />$ echo $USER<br />fedora</pre> <p>What happens here is variable expansion — the value stored in the variable is used in your command.</p> <p>Another useful variable is <em>$PATH</em>, that defines directories that your shell uses to look for binaries.</p> <h3>The $PATH variable<br /></h3> <p>There are many directories, or folders (the way they are called in graphical environments) that are important to the OS. Some directories are set to hold binaries you can use directly in your shell. And these directories are defined in the $PATH variable.</p> <pre class="wp-block-preformatted">$ echo $PATH<br />/usr/lib64/qt-3.3/bin:/usr/share/Modules/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/usr/libexec/sdcc:/usr/libexec/sdcc:/usr/bin:/bin:/sbin:/usr/sbin:/opt/FortiClient</pre> <p>This will help you when you want to have your own binaries (or scripts) accessible in the shell.</p></p> </div> |