Echo Command | Environment Variables in Linux | Linux Tutorials | Parsutech



Echo Command | Environment Variables in Linux | Linux Tutorials | Parsutech

Echo Command | Environment Variables in Linux | Linux Tutorials | Parsutech

Hello Friends ,
Please subscribe my youtube channel and also like my videos.
If you have any type of doubt then please put in the comment section .
Subscribe please!!!!

Stay Tuned!!!!!

Echo Command:-
The echo command in Linux and Unix-like operating systems is used to print text or messages to the terminal. It is a simple and commonly used command, often used in shell scripts or interactively at the command line. The basic syntax of the echo command is as follows:
Synatx:- echo [OPTIONS] [TEXT]

echo “Hello, World!” : You can use the echo command to display a message or text on the terminal.
This command will output “Hello, World!” to the terminal.

Variable Substitution: You can use the echo command to display the value of variables. For example:
my_variable=”Hello, Linux!”
echo $my_variable
This will output the value of the variable my_variable, which is “Hello, Linux!” in this case.

Newline Control: By default, echo adds a newline character at the end of the output. You can use the -n option to suppress the trailing newline: echo -n “This is on the same line.”

Escape Sequences: You can use escape sequences to include special characters in the output. For example, to add a newline character: echo “Line 1nLine 2”
This will display two lines with a newline character in between.

Backslash Escaping: If you want to print the actual backslash character, you can escape it with another backslash: echo “This is a backslash: \”

Multiple Arguments: You can use multiple arguments to print multiple strings: echo “Hello,” “World!”

The echo command is a fundamental tool for printing text and messages in the terminal and is often used in shell scripting and when working with the command line in Linux. It provides flexibility in formatting and displaying text as needed.

Variables in Linux:-
In Linux, environment variables can be categorized into two main types: system variables and user-defined variables.
System Variables:
System variables are set by the operating system or system services, and they are generally used to configure system-wide behavior and provide information about the system. Some common system variables include:
PATH: Specifies the directories where executable files are located.
HOME: Indicates the home directory of the user.
USER: Stores the name of the current user.
SHELL: Defines the default shell for the user.
LANG: Specifies the default system language.
TERM: Specifies the terminal type.
LOGNAME: Indicates the login name of the user.
HOSTNAME: Stores the hostname of the computer.
TZ: Specifies the time zone.
LD_LIBRARY_PATH: Lists directories where shared libraries are searched.
HISTFILE:-shows that which file is used as history file.
HISTSIZE:-shows that what is the size of history in terminal.
HISTFILESIZE:-shows that what is the of history in history file.
DISPLAY: Specifies the X display (used for GUI applications).
System variables are usually set during the system startup process and are accessible to all users and processes.

User-Defined Variables:
User-defined variables are variables that are set by users to meet their specific requirements. These variables are not predefined by the system and are created and managed by users. Users often use user-defined variables in shell scripts and for personal configurations. For example:

MY_VARIABLE: A variable created by the user to store a custom value.
DB_PASSWORD: A variable set to store a database password.
WORK_DIR: A variable set to specify a working directory for a specific project.
User-defined variables can be set and used on a per-user basis, and they are not typically available to other users or system-wide unless explicitly exported.

To create and use user-defined variables, you can typically set them in your shell configuration files like ~/.bashrc, ~/.bash_profile, or ~/.profile. For example:

export MY_VARIABLE=”Hello, World”
Once you’ve set a user-defined variable, you can access its value in your shell scripts or by typing echo $MY_VARIABLE in the terminal.

Remember that user-defined variables may not persist after you log out or restart your system, depending on where and how they are defined. To make them persistent, it’s often best to set them in your shell’s configuration files or in system-wide startup scripts if needed.