PLUGLINUX_HUB
Path: Royalchevron_rightModule 02.1

Bash Scripting Basics

Variables are the foundational building blocks of any script. They allow you to store data, reuse values, and make your scripts dynamic. In Bash, declaring a variable is straightforward, but it comes with a strict syntax rule: no spaces around the equals sign.

data_objectUnderstanding Variables

To assign a value to a variable, use the syntax variable_name="value".

example.sh
# Correct syntax (no spaces)
user_name="little_blue"
home_dir="/home/little_blue"

# Incorrect syntax (will cause errors)
user_name = "little_blue"

terminalInteractive Script Editor

~/scripts/hello.sh
psychology

task_alt Try it Yourself

Create a new script named info.sh. Define two variables: one for the current user and one for the current directory. Use echo to print a sentence combining both variables.

Start Challenge