HelloWorld
π Hello World - Your First Shell Script
π Overview
π― Your First Shell Script - Hello World
This guide walks you through creating and executing your first shell script, introducing the echo command and script execution basics.
π What This Guide Covers
- π Script Creation - Creating your first shell script file
- π§ Shebang - Understanding the script header
- π’ Echo Command - Printing output to the terminal
- π¨ Colored Output - Adding colors to your output
- π Permissions - Making scripts executable
- βΆοΈ Execution - Running your first script
π Creating Your First Script
Step 1: Create the Script File
Create a new file named helloworld.sh:
vi helloworld.sh
Or using other editors:
nano helloworld.sh
# or
cat > helloworld.sh << 'EOF'
EOF
π§ Basic Hello World Script
Step 2: Write the Script
Add the following content to your helloworld.sh file:
#!/bin/bash
echo "Hello World"
Explanation:
#!/bin/bash- Shebang directive specifying the Bash interpreterecho- Command to print text to the terminal"Hello World"- The text to be printed
π¨ Enhanced Hello World with Colors
Extended Script with Multiple Outputs
#!/bin/bash
echo "Hello World"
echo 'This is our first basic shell script'
echo -e "\033[0;31m β Fail message"
echo -e "\033[0;32m β
Success message"
echo -e "\033[0;33m β οΈ Warning message here"
Color Code Reference:
| Code | Color | Usage |
|---|---|---|
\033[0;31m | Red | Error/Fail messages |
\033[0;32m | Green | Success messages |
\033[0;33m | Yellow | Warning messages |
\033[0;34m | Blue | Information |
\033[0m | Reset | Reset to default color |
Note: Use echo -e flag to enable interpretation of backslash escapes.
π Making the Script Executable
Step 3: Add Execute Permission
Before running the script, make it executable:
chmod +x helloworld.sh
Explanation:
chmod- Change file mode/permissions+x- Add execute permissionhelloworld.sh- The script file
βΆοΈ Running Your Script
Step 4: Execute the Script
Run your script using one of these methods:
Method 1: Direct Execution (with shebang)
./helloworld.sh
Method 2: Explicit Interpreter
bash helloworld.sh
Method 3: Source Command
source helloworld.sh
# or
. helloworld.sh
π Expected Output
Basic Script Output
Hello World
Enhanced Script Output
Hello World
This is our first basic shell script
β Fail message
β
Success message
β οΈ Warning message here
π‘ Key Concepts
| Concept | Description |
|---|---|
| Shebang | #!/bin/bash tells the system to use Bash interpreter |
| Echo | Prints text to standard output (terminal) |
| Permissions | chmod +x makes the file executable |
| Execution | ./script.sh runs the script from current directory |
| Color Codes | ANSI escape sequences for colored output |
β Best Practices
- Always include a shebang at the beginning
- Use meaningful script names with
.shextension - Make scripts executable with
chmod +x - Add comments to explain what your script does
- Test scripts before using them in production
- Use echo for simple output, printf for complex formatting
π Navigation
β¬ οΈ Previous: Module 1: Shebang and Execution
π Current Location: Hello World - Your First Script (You are here)
β‘οΈ Next Step: Comments and Documentation
πΊοΈ Full Path: Introduction β Overview β Module 2: Basics β Hello World
π Additional Resources
- π Bash Manual - Echo: gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
- π ANSI Color Codes: en.wikipedia.org/wiki/ANSI_escape_code
- π Chmod Permissions: linux.die.net/man/1/chmod
π Congratulations! Your First Script is Complete! π
Comments
π¬ Comments and Documentation
π Overview
π― Master Comments and Code Documentation
This guide covers how to write effective comments in shell scripts, including single-line and multi-line comment techniques.
π What This Guide Covers
- π Single-Line Comments - Basic comment syntax
- π Multi-Line Comments - Advanced comment techniques
- π‘ Best Practices - Writing effective documentation
- π― Use Cases - When and why to use comments
- π Documentation - Creating maintainable code
π What are Comments?
Comments are useful information that developers provide to make the code easier to understand. They are ignored by the shell interpreter and do not affect script execution.
Benefits of Comments:
- Explain complex logic
- Document script purpose
- Help other developers understand code
- Serve as reminders for future modifications
- Improve code maintainability
π€ Single-Line Comments
Syntax
A single-line comment starts with a hash symbol (#) with no whitespace before it and lasts until the end of the line.
#!/bin/bash
# This is a single-line comment
echo "Hello World" # This is also a comment
Examples
#!/bin/bash
# Script: helloworld.sh
# Purpose: Print a greeting message
# Author: Your Name
# Date: 2024-01-01
# Print greeting
echo "Hello World"
# Print additional message
echo "Welcome to Shell Scripting"
Multi-Line Single Comments
If your comment exceeds one line, place a hash symbol on each line:
#!/bin/bash
# This is a long comment that spans
# multiple lines. Each line starts
# with a hash symbol for clarity.
echo "Script starts here"
π Multi-Line Comments
Method 1: Using Colon and Quotes
The most common method uses a colon (:) followed by a single quote to open and close multi-line comments:
#!/bin/bash
: '
This is a multi-line comment
It can span multiple lines
without needing a hash on each line
'
echo "Script continues here"
Important: There must be a space between : and the opening quote.
Method 2: Using Here Document
Another method uses a here document with <<'END_COMMENT':
#!/bin/bash
: <<'END_COMMENT'
This is a multi-line comment using
a here document syntax. This method
is useful for longer documentation blocks.
END_COMMENT
echo "Script continues here"
Method 3: Using Colon and Parentheses
#!/bin/bash
: (
This is another way to write
multi-line comments in shell scripts
)
echo "Script continues here"
π‘ Comment Best Practices
Header Comments
Always start your script with a header comment:
#!/bin/bash
################################
# Script: backup.sh
# Purpose: Backup important files
# Author: Your Name
# Date: 2024-01-01
# Version: 1.0
################################
Inline Comments
Use inline comments to explain complex logic:
#!/bin/bash
# Check if file exists
if [ -f "$filename" ]; then
# File exists, proceed with processing
process_file "$filename"
else
# File not found, display error
echo "Error: File not found"
fi
Section Comments
Organize code into sections with clear comments:
#!/bin/bash
# ============================================
# CONFIGURATION SECTION
# ============================================
CONFIG_FILE="/etc/myapp/config.conf"
LOG_FILE="/var/log/myapp.log"
# ============================================
# FUNCTION DEFINITIONS
# ============================================
function backup_files() {
# Implementation here
:
}
# ============================================
# MAIN SCRIPT
# ============================================
backup_files
π Comment Examples
Complete Script with Comments
#!/bin/bash
################################
# Script: user_info.sh
# Purpose: Display user information
# Author: DevOps Team
# Date: 2024-01-01
################################
# Get current user
CURRENT_USER=$(whoami)
# Get user ID
USER_ID=$(id -u)
# Display information
echo "Current User: $CURRENT_USER"
echo "User ID: $USER_ID"
: '
This section demonstrates multi-line comments
You can use this for longer explanations
or temporarily disabling code blocks
'
# Display home directory
echo "Home Directory: $HOME"
β Do's and Don'ts
| Do β | Don't β |
|---|---|
| Write clear, concise comments | Write obvious comments |
| Update comments when code changes | Leave outdated comments |
| Use comments to explain "why" | Use comments to explain "what" (code is self-explanatory) |
| Comment complex logic | Over-comment simple code |
| Use consistent comment style | Mix different comment styles |
| Document assumptions | Assume readers know your intent |
π Navigation
β¬ οΈ Previous: Hello World - Your First Script
π Current Location: Comments and Documentation (You are here)
β‘οΈ Next Step: Escape Sequences and Special Characters
πΊοΈ Full Path: Module 2: Basics β Hello World β Comments β Escape Sequences β User Variables β System Variables
π Additional Resources
- π Bash Manual - Comments: gnu.org/software/bash/manual
- π Shell Scripting Guide: tldp.org/LDP/abs
- π‘ Code Documentation Best Practices: en.wikipedia.org/wiki/Comment_(computer_programming)
π Great Job! Comments and Documentation Complete! π
Escape
π Escape Sequences and Special Characters
π Overview
π― Master Escape Sequences and Special Characters
This guide covers escape sequences, special characters, and line continuation techniques for advanced text formatting in shell scripts.
π What This Guide Covers
- π Escape Character - Understanding the backslash
- π Escape Sequences - Common escape sequences and their uses
- π¨ Text Formatting - Tabs, newlines, and spacing
- π Line Continuation - Breaking long commands across lines
- π¬ Quoting - Single vs double quotes and escaping
- π Examples - Practical escape sequence usage
π What is an Escape Character?
The escape character (\) is a non-quoted backslash that tells the shell to interpret the following character literally. It preserves the literal value of the next character that follows, with the exception of <newline>.
Key Points:
- Backslash (
\) is the escape character - Escapes the special meaning of the next character
- Different behavior in single vs double quotes
- Can be used for line continuation
π Common Escape Sequences
Escape Sequence Reference Table
| Sequence | Name | Description | Example |
|---|---|---|---|
\n | Newline | Line break | echo -e "Line1\nLine2" |
\t | Tab | Horizontal tab | echo -e "Col1\tCol2" |
\v | Vertical Tab | Vertical tab | echo -e "Line1\vLine2" |
\r | Carriage Return | Return to line start | echo -e "Text\rOverwrite" |
\\ | Backslash | Literal backslash | echo "\\" |
\" | Double Quote | Literal quote | echo "He said \"Hi\"" |
\' | Single Quote | Literal quote | echo 'It\'s' |
\$ | Dollar Sign | Literal dollar | echo "\$100" |
\0 | Null Character | Null byte | echo -e "\0" |
π¨ Text Formatting with Escape Sequences
Newline Escape (\n)
#!/bin/bash
echo -e "Line 1\nLine 2\nLine 3"
Output:
Line 1
Line 2
Line 3
Tab Escape (\t)
#!/bin/bash
echo -e "Name\tAge\tCity"
echo -e "John\t25\tNew York"
echo -e "Jane\t30\tLos Angeles"
Output:
Name Age City
John 25 New York
Jane 30 Los Angeles
Vertical Tab Escape (\v)
#!/bin/bash
echo -e "Line 1\vLine 2\vLine 3"
Output:
Line 1
Line 2
Line 3
Carriage Return Escape (\r)
#!/bin/bash
echo -e "Processing...\rComplete!"
Output:
Complete!
π Line Continuation
Using Backslash for Line Continuation
If a \<newline> pair appears and the backslash is not quoted, the \<newline> is treated as a line continuation (removed from input stream).
#!/bin/bash
# Long command split across multiple lines
echo "This is a very long message that \
spans multiple lines for better \
readability in the source code"
Output:
This is a very long message that spans multiple lines for better readability in the source code
Practical Example: Long Commands
#!/bin/bash
# Complex command with line continuation
find /home \
-type f \
-name "*.txt" \
-mtime -7 \
-exec ls -lh {} \;
π¬ Quoting and Escaping
Single Quotes vs Double Quotes
#!/bin/bash
# Single quotes - escape character taken literally
echo 'my \
name \
is \
devopsgurupro'
# Double quotes - newline escaped (line continuation)
echo "my \
name \
is \
devopsgurupro"
Escaping Special Characters
#!/bin/bash
# Escape dollar sign
echo "The price is \$100"
# Escape double quotes
echo "He said \"Hello World\""
# Escape backslash
echo "Path: C:\\Users\\Documents"
π Complete Examples
Example 1: Formatted Output
#!/bin/bash
# owner: devopsgurupro
# purpose: print formatted output
echo "########### Script Starting ########"
echo "Purpose: Going to install nginx"
echo "####################################"
echo ""
echo -e "Service\tStatus\tPort"
echo -e "nginx\tRunning\t80"
echo -e "mysql\tStopped\t3306"
Output:
########### Script Starting ########
Purpose: Going to install nginx
####################################
Service Status Port
nginx Running 80
mysql Stopped 3306
Example 2: Multi-line Strings
#!/bin/bash
# Display multi-line message
echo "my
name
is
devopsgurupro"
Output:
my
name
is
devopsgurupro
Example 3: Complex Formatting
#!/bin/bash
echo -e "this is devopsgurupro \t devopsgurupro \t test name"
echo -e "this is devopsgurupro \v devopsgurupro \v test name"
echo -e "this is devopsgurupro \n devopsgurupro \n test name"
Output:
this is devopsgurupro devopsgurupro test name
this is devopsgurupro
devopsgurupro
test name
this is devopsgurupro
devopsgurupro
test name
β Best Practices
- Use
echo -eto enable escape sequence interpretation - Use
printffor more complex formatting needs - Be careful with backslashes in file paths (Windows paths)
- Use line continuation for long commands for readability
- Test escape sequences in different shells (bash, sh, zsh)
- Document escape sequences in comments for clarity
- Use single quotes when you don't want escape interpretation
π Navigation
β¬ οΈ Previous: Comments and Documentation
π Current Location: Escape Sequences and Special Characters (You are here)
β‘οΈ Next Step: User-Defined Variables
πΊοΈ Full Path: Module 2: Basics β Hello World β Comments β Escape Sequences β User Variables β System Variables
π Additional Resources
- π Bash Manual - Echo: gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
- π Printf Documentation: linux.die.net/man/1/printf
- π ANSI Escape Codes: en.wikipedia.org/wiki/ANSI_escape_code
π Excellent! Escape Sequences Complete! π
Variables
π User-Defined Variables
π Overview
π― Master User-Defined Variables in Shell Scripting
This guide covers how to create, assign, and use custom variables defined by users in shell scripts, including naming conventions and best practices.
π What This Guide Covers
- π Variable Definition - Creating custom variables
- π€ Naming Rules - Valid and invalid variable names
- βοΈ Assignment - How to assign values to variables
- π― Variable Expansion - Using variables in scripts
- π‘ Best Practices - Naming conventions and standards
- π Examples - Practical variable usage
π What are User-Defined Variables?
User-defined variables are custom variables created by the user (programmer) in shell scripts. Unlike system variables which are predefined by the shell, user-defined variables are created as needed for specific purposes in your scripts.
Definition: Variables created and managed by the user for storing custom data in scripts.
Key Points:
- Created by the user/programmer
- Store custom data values
- Can be referenced by their name
- Are case-sensitive
- Can be modified during script execution
π Variable Naming Rules
Valid Variable Names
The name of a variable can contain:
- Letters (a-z, A-Z)
- Numbers (0-9)
- Underscore character (_)
Valid Examples:
_VARIABLE_NAME
VARIABLE_NAME
VARIABLE_1_NAME
vARIABLE_2_NAME
my_var
count
USER_ID
Invalid Variable Names
Invalid Examples:
2_VARNAME # Cannot start with a number
-VARIABLENAME # Cannot contain hyphen
VARIABLE-SOMENAME # Cannot contain hyphen
SOMENAME_A! # Cannot contain special characters
my var # Cannot contain spaces
Naming Conventions
| Convention | Example | Usage |
|---|---|---|
| UPPERCASE | MY_MESSAGE | Environment and global variables |
| lowercase | my_message | Local variables |
| camelCase | myMessage | Not recommended in shell |
| snake_case | my_message | Preferred for readability |
βοΈ Variable Assignment
Basic Syntax
variable_name=variable_value
Important: There must be no spaces around the = sign.
Correct vs Incorrect
# β
CORRECT
MY_MESSAGE="Hello World"
name="John"
age=25
# β INCORRECT
MY_MESSAGE = "Hello World" # Spaces around =
name= "John" # Space after =
age =25 # Space before =
Why Spaces Matter
VAR=value- Shell sees=and treats it as variable assignmentVAR = value- Shell assumesVARis a command and tries to execute it
π Variable Expansion
Using Variables
To use a variable, prefix it with $:
#!/bin/bash
name="devopsgurupro"
age="20"
# Using variables
echo $name
echo $age
echo "My name is $name and my age is $age"
Variable Expansion Methods
| Method | Example | Usage |
|---|---|---|
| $variable | $name | Simple expansion |
| ${variable} | ${name} | Explicit expansion (recommended) |
| "$variable" | "$name" | Expansion in double quotes |
| '$variable' | '$name' | No expansion in single quotes |
Practical Examples
#!/bin/bash
work="programm"
var="ing"
# Without braces - may cause issues
echo "i am $working" # Output: i am (empty)
# With braces - correct
echo "i am ${work}ing" # Output: i am programming
echo "i am ${work}${var}" # Output: i am programming
π Complete Variable Examples
Example 1: Basic Variable Usage
#!/bin/bash
# Script: user_info.sh
# Purpose: Display user information
name="devopsgurupro"
age="20"
city="New York"
echo "Name: ${name}"
echo "Age: ${age}"
echo "City: ${city}"
echo "My name is ${name} and I am ${age} years old from ${city}"
Output:
Name: devopsgurupro
Age: 20
City: New York
My name is devopsgurupro and I am 20 years old from New York
Example 2: Case-Sensitive Variables
#!/bin/bash
# Variables are case-sensitive
name="dgpro"
NAME="devopsgurupro"
nAmE="amit"
echo "${name} ${NAME} ${nAmE}"
Output:
dgpro devopsgurupro amit
Example 3: Variable Concatenation
#!/bin/bash
_variableName="first variable"
variable2Name="second variable"
variable_name="vartest"
echo "${_variableName}"
echo "${variable2Name}"
echo "${variable_name}"
Output:
first variable
second variable
vartest
π¦ Variable Types
String Variables
#!/bin/bash
message="Hello World"
name="John Doe"
echo "$message, $name"
Numeric Variables
#!/bin/bash
count=10
age=25
price=99.99
echo "Count: $count, Age: $age, Price: $price"
Environment Variables
#!/bin/bash
# Pre-defined system variables
echo "Home: $HOME"
echo "User: $USER"
echo "Shell: $SHELL"
echo "Path: $PATH"
β Best Practices
- Use
${variable}syntax for clarity and to avoid ambiguity - Use UPPERCASE for global/environment variables
- Use lowercase or snake_case for local variables
- Always quote variables:
"${variable}"to handle spaces - Use meaningful variable names
- Initialize variables before use
- Document variable purpose with comments
- Avoid using reserved words as variable names
π Navigation
β¬ οΈ Previous: Escape Sequences and Special Characters
π Current Location: User-Defined Variables (You are here)
β‘οΈ Next Step: System-Defined Variables
πΊοΈ Full Path: Module 2: Basics β Hello World β Comments β Escape Sequences β User Variables β System Variables
π Additional Resources
- π Bash Manual - Variables: gnu.org/software/bash/manual/html_node/Bash-Variables.html
- π Shell Parameter Expansion: pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
- π‘ Variable Naming Conventions: en.wikipedia.org/wiki/Naming_convention_(programming)
π Excellent! User-Defined Variables Complete! π
SystemDefineVariable
π₯οΈ System-Defined Variables
π Overview
π― Master System-Defined Variables in Shell Scripting
This guide covers environment variables created and maintained by the Linux bash shell, including how to view, modify, and use them effectively.
π What This Guide Covers
- π₯οΈ System Variables - Understanding built-in shell variables
- π Common Variables - Most frequently used environment variables
- π§ Commands - Tools to list and manage variables
- π‘ Practical Examples - Real-world usage scenarios
- βοΈ Configuration - Modifying system variables
- π Examples - Working with environment variables
π₯οΈ What are System Variables?
System variables (also called environment variables) are created and maintained by the Linux bash shell itself. These variables are typically defined in CAPITAL LETTERS and control various aspects of the shell's behavior.
Key Characteristics:
- Created and maintained by the shell
- Usually written in UPPERCASE
- Control shell behavior and system configuration
- Available to all child processes
- Can be modified to customize shell behavior
π§ Commands to Manage Variables
Variable Management Commands
| Command | Purpose | Usage |
|---|---|---|
| env | List environment variables | env or env | grep VAR |
| printenv | Print environment variables | printenv or printenv HOME |
| set | Set/unset shell variables | set or set -x |
| unset | Delete variables | unset VARIABLE_NAME |
| export | Set environment variables | export VARIABLE_NAME=value |
Command Details
env Command
# List all environment variables
env
# Run program with custom environment
env CUSTOM_VAR=value ./script.sh
# Search for specific variable
env | grep PATH
printenv Command
# Print all environment variables
printenv
# Print specific variable
printenv HOME
printenv USER
set Command
# List all variables (including shell functions)
set
# Enable debug mode
set -x
# Disable debug mode
set +x
unset Command
# Delete a variable
unset MY_VARIABLE
# Verify deletion
echo $MY_VARIABLE # Output: (empty)
export Command
# Create environment variable
export MY_VAR="value"
# Make variable available to child processes
export PATH="/usr/local/bin:$PATH"
π Common System Variables
Essential Environment Variables
| Variable | Description | Example |
|---|---|---|
| USER | Current logged-in user | devopsgurupro |
| HOME | Home directory of current user | /home/devopsgurupro |
| SHELL | Path to current user's shell | /bin/bash |
| PATH | Directories to search for commands | /usr/local/bin:/usr/bin:/bin |
| PWD | Present working directory | /home/devopsgurupro/projects |
| HOSTNAME | Machine hostname | dgpro-server |
| UID | User ID | 1000 |
| PPID | Parent process ID | 1234 |
| LANG | Current locale settings | en_US.UTF-8 |
| TERM | Terminal emulation type | xterm-256color |
| OSTYPE | Operating system type | linux-gnu |
| SECONDS | Seconds since script started | 42 |
| EDITOR | Default text editor | /usr/bin/nano |
| LOGNAME | Login name of user | devopsgurupro |
π Practical Examples
Example 1: Display System Variables
#!/bin/bash
# Script: system_variables.sh
# Purpose: Display common system variables
echo "=== System Information ==="
echo "Current User: ${USER}"
echo "Home Directory: ${HOME}"
echo "Shell: ${SHELL}"
echo "Hostname: ${HOSTNAME}"
echo "User ID: ${UID}"
echo "Present Working Directory: ${PWD}"
echo "Operating System: ${OSTYPE}"
echo "Terminal Type: ${TERM}"
Output:
=== System Information ===
Current User: devopsgurupro
Home Directory: /home/devopsgurupro
Shell: /bin/bash
Hostname: dgpro-server
User ID: 1000
Present Working Directory: /home/devopsgurupro/projects
Operating System: linux-gnu
Terminal Type: xterm-256color
Example 2: Working with PATH
#!/bin/bash
# Script: path_info.sh
# Purpose: Display and modify PATH
echo "Current PATH:"
echo ${PATH}
echo ""
echo "Adding custom directory to PATH:"
export PATH="/usr/local/custom/bin:${PATH}"
echo ${PATH}
Example 3: Process Information
#!/bin/bash
# Script: process_info.sh
# Purpose: Display process-related variables
echo "Current Process ID: $$"
echo "Parent Process ID: ${PPID}"
echo "Script Execution Time: ${SECONDS} seconds"
# Wait and show elapsed time
sleep 5
echo "Elapsed Time: ${SECONDS} seconds"
Output:
Current Process ID: 12345
Parent Process ID: 1234
Script Execution Time: 0 seconds
Elapsed Time: 5 seconds
Example 4: Complete System Variables Script
#!/bin/bash
# Script: complete_system_vars.sh
# Purpose: Demonstrate all system variables
echo "=== User Information ==="
echo "User: ${USER}"
echo "Login Name: ${LOGNAME}"
echo "Home: ${HOME}"
echo "UID: ${UID}"
echo ""
echo "=== System Information ==="
echo "Hostname: ${HOSTNAME}"
echo "OS Type: ${OSTYPE}"
echo "Shell: ${SHELL}"
echo "Terminal: ${TERM}"
echo ""
echo "=== Path Information ==="
echo "Current Directory: ${PWD}"
echo "PATH: ${PATH}"
echo ""
echo "=== Process Information ==="
echo "Process ID: $$"
echo "Parent Process ID: ${PPID}"
echo "Seconds Elapsed: ${SECONDS}"
echo ""
echo "=== Locale Information ==="
echo "Language: ${LANG}"
βοΈ Modifying System Variables
Temporary Modification
#!/bin/bash
# Modify variable for current session only
export MY_CUSTOM_VAR="custom_value"
echo ${MY_CUSTOM_VAR}
# Modify PATH temporarily
export PATH="/new/path:${PATH}"
Permanent Modification
Add to shell configuration file (~/.bashrc or ~/.bash_profile):
# Add custom directory to PATH
export PATH="/usr/local/custom/bin:${PATH}"
# Set custom variables
export EDITOR="nano"
export LANG="en_US.UTF-8"
Unsetting Variables
#!/bin/bash
# Remove a variable
unset MY_VARIABLE
# Verify it's removed
echo ${MY_VARIABLE} # Output: (empty)
π‘ Best Practices
- Always use
${VARIABLE}syntax for clarity - Use
exportto make variables available to child processes - Document custom variables in scripts
- Be cautious when modifying system variables like PATH
- Use
printenvto verify variable values - Avoid overwriting important system variables
- Use meaningful names for custom variables
- Test variable modifications in non-production environments first
π Navigation
β¬ οΈ Previous: User-Defined Variables
π Current Location: System-Defined Variables (You are here)
β‘οΈ Next Step: Module 3: Control Flow
πΊοΈ Full Path: Module 2: Basics β Hello World β Comments β Escape Sequences β User Variables β System Variables
π Additional Resources
- π Bash Manual - Variables: gnu.org/software/bash/manual/html_node/Bash-Variables.html
- π Environment Variables Guide: tldp.org/LDP/abs/html/internalvariables.html
- π Linux Environment Variables: linux.com/training-tutorials/linux-environment-variables
π Excellent! System Variables Complete! π