LPIC-101.
With Linux occupying the central position in my tech universe over the past couple of months, it presents the perfect opportunity for me to share the knowledge I have accumulated throughout my certification study journey.
This month, Linux has taken center stage in my tech universe. It’s safe to say that the open-source operating system is the driving force behind my ongoing tech renaissance. Whether I’m coding in Bash script to construct my home network server or developing the backend server system for my forthcoming mobile app, Linux is my Disneyland.
Since last year, I have been diligently working towards obtaining my LPIC Level 1 certification. Although LPIC may not enjoy the same level of recognition as CCNA, it remains highly regarded as one of the top certifications for Linux administrators, validating their proficiency in Linux.
After my recent remarkable encounters with coding in Bash script, which left both my supervisor and team leaders astounded, my internal drive to fully immerse myself in the Linux realm and acquire a deep understanding of its fundamentals through certification has been reignited.
In addition to the Linux-related series already featured on my blog, I am now introducing a new one titled Road to LPIC. This series will revolve around my LPIC studying journey and serve as a platform for me to share my Linux knowledge with readers and fellow Linux enthusiasts.
Given the vastness of my LPIC journey, it’s impossible for me to cover every aspect. Therefore, I will focus on sharing newfound discoveries and unfamiliar terms that I encounter along the way during my study journey.
To beging with, let’s learn about set and env command! Here we go!!!
set command:
$ echo $TEST ##define a variab;e called TEST
$ TEST="SE" ## substitute SE to TEST
$ echo $TEST ## confirm SE in substituted in TEST
SE
$ set | grep TEST ## confirm TEST variable is defined with set command
TEST=SE
$ unset TEST ## delete the TEST variable
$ echo $TEST ## confirm TEST variable is deleted
$ set | grep TEST ## confirm TEST variable is undefined with set command====
In Linux, the set
command is a built-in command used to manipulate shell and environment variables. It allows you to view and modify the values of variables that control the behavior and settings of the shell session.
When used without any arguments, the set
command displays all shell variables and their values, including both local variables specific to the current shell session and environment variables inherited from the parent process.
Here are a few common uses of the set
command with arguments:
set variable=value
: This form is used to set the value of a shell variable. For example,set myvar=hello
assigns the value “hello” to the variablemyvar
.set -e
orset -o errexit
: This enables the “exit immediately if any command exits with a non-zero status” behavior, also known as “errexit” or “exit on error.”set -u
orset -o nounset
: This causes the shell to treat unset variables as an error and produce an error message if an unset variable is encountered.set -x
orset -o xtrace
: This enables the “xtrace” or “debug” mode, which displays each command before it is executed, providing a detailed trace of the script’s execution.
These are just a few examples of how the set
command can be used in Linux. For more information and options, you can refer to the command’s manual page by running man set
in your terminal.\\\\\\\\\\
env command:
$ export TEST="SE"
$ env | grep "TEST"
TEST=SE
$ unset TEST
In Linux, the env
command is used to display or modify the environment variables for the current shell session or execute a command within a modified environment.
When used without any arguments, the env
command displays a list of environment variables and their values for the current shell session.
Here are a few common uses of the env
command:
env
: This displays the complete list of environment variables and their values.env variable=value command
: This executes a command with a modified environment where a specific environment variable is set to a particular value. For example,env LANG=fr_FR.UTF-8 date
executes thedate
command with theLANG
variable set to the French locale.env -i command
: This executes a command within an empty environment, meaning no environment variables are inherited by the command. It provides a clean and minimal environment for running commands.env -u variable command
: This executes a command with a specific environment variable unset or removed. For example,env -u MYVAR echo $MYVAR
runs theecho
command without theMYVAR
variable in the environment.
The env
command is versatile and useful for managing and inspecting environment variables in Linux. You can refer to the command’s manual page by running man env
in your terminal for more details and options.