guest@termux:~$ cat automate-tasks-using-bash-scripts.md
Automate Tasks Using Bash Scripts
Learn how to automate tasks in Termux using simple Bash scripts for backups, commands, and daily workflows.
What Is a Bash Script?
A Bash script is a file that contains Linux commands that run automatically.
Instead of typing the same commands repeatedly, you can save them inside a script and execute everything with one command.
Bash scripts are useful for:
- Automating tasks
- Running backups
- Cleaning files
- Starting tools
- Saving time
Create Your First Script
Create a new file:
nano hello.sh
Add this:
#!/bin/bash
echo "Hello from Termux"
Save the file.
Make the Script Executable
Run:
chmod +x hello.sh
This gives execution permission.
Run the Script
Execute the script:
./hello.sh
Output:
Hello from Termux
Example: Update Termux Automatically
Create a script:
nano update.sh
Add:
#!/bin/bash
pkg update -y && pkg upgrade -y
echo "System Updated"
Save and make it executable:
chmod +x update.sh
Run it:
./update.sh
Example: Backup a Folder
Create a backup script:
nano backup.sh
Add:
#!/bin/bash
cp -r /storage/emulated/0/Documents /storage/emulated/0/Backup
echo "Backup Completed"
Run:
chmod +x backup.sh
./backup.sh
Useful Bash Commands
Print text:
echo "Hello"
Pause script:
sleep 5
Create folder:
mkdir test
Delete file:
rm file.txt
Run Scripts From Anywhere
Move scripts to:
~/bin
Example:
mkdir -p ~/bin
mv hello.sh ~/bin
Now you can run:
hello.sh
from anywhere.
Common Error
Permission Denied
Fix it with:
chmod +x script.sh
Final Thoughts
Bash scripting is one of the best ways to automate tasks in Termux.
Start with small scripts, then slowly build more advanced automation workflows as you learn Linux commands.
guest@termux:~$ whoami
guest@termux:~$ subscribe --email you@example.com
Get new guides delivered to your inbox. No spam, unsubscribe anytime.