📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Linux Command Line Variables in Scripts

Variables in Scripts

5 min read
Script arguments are in $1, $2, etc. $# is the count and $@ is all arguments. Read interactive input with read -p 'Prompt: ' VAR. Use ${VAR:-default} as a fallback value when a variable might be empty.

Script Variables

#!/bin/bash
NAME="Alice"
AGE=30

echo "Name: $NAME, Age: $AGE"
echo "Script: $0"    # script name
echo "Arg 1: $1"    # first argument
echo "All args: $@"
echo "Arg count: $#"

# Read input
read -p "Enter name: " INPUT
echo "Hello, $INPUT!"