Termux Shell Scripting & Aliases

Shell Script

Create The Script

nano script.sh
chmod +x script.sh
chmod +x script.sh
Make it executable (required)

Inside The File

#!/data/data/com.termux/files/usr/bin/bash

echo "Hello"
which bash
pkg install which
#!/data/data/com.termux/files/usr/bin/bash
  • #! is shebang
  • Must be first line
  • No spaces before it
  • Defines interpreter
  • File must be executable
which bash
Get bash path for shebang

Termux Widget

mkdir -p ~/.shortcuts
mv script.sh ~/.shortcuts/
  • The widget only reads scripts inside “~/.shortcuts/”

Alias

An alias lets you create a shortcut for a longer command

Temporary Alias (Current Session Only)

alias name='command'
alias ll='ls -la'
alias ll='ls -la'
When you type “ll”
it will run “ls -la”
  • This will disappear when you close Termux

Make It Permanent

nano ~/.bashrc
alias ll='ls -la'
alias la='ls -a'
alias cls='clear'
alias update='pkg update && pkg upgrade'
source ~/.bashrc
nano ~/.bashrc
Add aliases to your ~/.bashrc file
source ~/.bashrc
Apply changes(Or just restart Termux)

View And Remove

alias
unalias name
alias
List all aliases
unalias
Remove an alias