Bash scripting is the fastest way to go from typing single commands to automating real work on Android. This cheat sheet covers the essentials you need to write your first scripts — and every example below works in Linux Master (Terminal Pro), whether you use the safe virtual shell or the real bash terminal.

1. Your first script

Every bash script starts with a shebang line that tells the phone which interpreter to use:

#!/bin/bash echo "Hello from my phone"

Save it as hello.sh, make it executable with chmod +x hello.sh, then run it with ./hello.sh.

2. Variables

  • Set a variable: name="Ada" (no spaces around =)
  • Use it: echo "Hello, $name"
  • Read input: read -p "Your name: " name

3. Conditionals

if [ "$name" = "root" ]; then echo "Admin access" else echo "Standard user" fi

Common tests: -eq, -ne, -gt for numbers; =, != for strings; -f file, -d dir, -x file for file checks.

4. Loops

for f in *.txt; do echo "Processing $f" done

Loop over files, numbers (for i in {1..5}) or command output (for ip in $(hostname -I)).

5. Functions

backup() { tar -czf "$1.tar.gz" "$1" } backup documents

Give repeated tasks a name, pass arguments ($1, $2), and call them anywhere in the script.

6. Exit codes and arguments

  • $0 — script name
  • $# — number of arguments
  • $? — exit code of the last command (0 means success)
  • exit 1 — stop with an error

Practise without breaking anything

Type these examples in Linux Master’s virtual shell first — it simulates a Linux filesystem so you can test loops, functions and file operations with zero risk. When a script works, run it for real in the native bash terminal. The app’s Daily Challenge and typed-answer tasks then drill you on the same patterns until they stick.

Next step: copy one snippet above into Linux Master (Terminal Pro) — free on Google Play, offline, 1,000+ commands included.