Bash User Defined Variables

User-defined variables are created by you (the user) in a shell or script to store temporary values, messages, or configurations.

They are not predefined by the system.

prabhumanyam@PrabhuPC:~$ mine="Sandeep"
prabhumanyam@PrabhuPC:~$ echo $mine
Sandeep

prabhumanyam@PrabhuPC:~$ unset mine
prabhumanyam@PrabhuPC:~$ echo $mine


prabhumanyam@PrabhuPC:~$ mine="Sandeep"
prabhumanyam@PrabhuPC:~$ readonly mine
prabhumanyam@PrabhuPC:~$ unset mine
-bash: unset: mine: cannot unset: readonly variable

prabhumanyam@PrabhuPC:~$ name = "Prabhu"
Command 'name' not found, did you mean:

========================================
Rules for User-Defined Variables

No spaces around =
✅ name="Prabhu"
❌ name = "Prabhu"
  1. Variable names can contain letters, numbers, and underscores (_)
  2. Variable names cannot start with a number
  3. Use $ to access the value — e.g. echo $name
  4. By default, variables are local to the current shell or script
  5. Use export to make them available to child processes.
========================================
prabhumanyam@PrabhuPC:~$ cat uservariable.sh
#!/bin/bash
# 🧩 USER-DEFINED VARIABLES
echo "============================================="
echo "        👤 USER-DEFINED VARIABLES"
echo "============================================="

# Define variables
name="Prabhu"
role="QA Engineer"
experience="7 Years"
domain="ETL / Big Data Testing"
company="Oracle Financial Services"
location="Bangalore"

# Exported variable (can be used by child scripts)
export greeting="Hello, $name! Welcome to $company."

# Arithmetic example
a=10;
b=30;
sum=$((a+b))


# Display user-defined variable values
echo "Name        : $name"
echo "Role        : $role"
echo "Experience  : $experience"
echo "Domain      : $domain"
echo "Company     : $company"
echo "Location    : $location"
echo "Sum Example : $a + $b = $sum"
echo "Greeting    : $greeting"
echo "My Name is : $name and My role in company is : $role"
echo "---------------------------------------------"


prabhumanyam@PrabhuPC:~$ sh uservariable.sh
=============================================
        👤 USER-DEFINED VARIABLES
=============================================
Name        : Prabhu
Role        : QA Engineer
Experience  : 7 Years
Domain      : ETL / Big Data Testing
Company     : Oracle Financial Services
Location    : Bangalore
Sum Example : 10 + 30 = 40
Greeting    : Hello, Prabhu! Welcome to Oracle Financial Services.
My Name is : Prabhu and My role in company is : QA Engineer
---------------------------------------------