If you have ever tried Install an APK, move files, and launch a .sh script on Android And all you got was an annoying "permission denied" message? Don't worry, you're not alone. Android isn't your typical desktop Linux, and while they share many fundamental principles, the permissions and paths system complicates things a bit.
In this article we're going to see, step by step, how Create and run .sh scripts in Termux for AndroidLearn how to solve common permission problems and how to get the most out of this app to automate tasks when you start your device, share links, or even use widgets. All of this is explained in clear language, with real-world examples and tips that will save you time and headaches.
What is Termux and why is it ideal for .sh scripts on Android?

Termux is an application that allows you to have a complete Linux environment within Android, without needing root access. It's not just a terminal emulator: it includes a Debian/Ubuntu-style package manager, with which you can install Python, Ruby, Node.js, gcc, ssh, web servers, databases, and much more.
What's interesting for our case is that Termux offers a real shell (bash, zsh…)It offers support for scripts, keyboard shortcuts, mouse input, and a package system very similar to that of a classic distro. Basically, you can use it for programming, server administration, or simply automating your Android system with .sh scripts.
From the very first start you'll see that you can use Useful Termux commands , the ls, grep, nano, vim, htop, git, pythonetc. However, the directory hierarchy is not exactly the same as in a desktop Linux system, and this detail is crucial when we talk about scripts.
In addition, Termux supports physical keyboards and special shortcutsFor example, the volume down key acts as the Ctrl key, allowing you to use combinations like Ctrl+C, Ctrl+D, or Ctrl+L, making the experience much more convenient on a mobile phone or tablet.
Install Termux correctly and avoid version conflicts

One of the problems that is often mentioned is that, after installing Termux, The app icon doesn't appear or it gives strange errorsThis often happens because of installing old or mixed versions from Google Play and F-Droid.
The current recommendation is that Install Termux from a single trusted sourceIt's generally recommended to use F-Droid, where the maintained version is located, or failing that, the official version from GitHub. If you choose F-Droid, download the Termux APK directly and avoid mixing it with the Play Store version.
This is especially important if you are going to use plugins like Termux:Boot, Termux:API or Termux:WidgetIf you need a guide, Learn how to use TermuxAll related apps must come from the same store (Play Store or F-Droid) for the digital signature to match. If you mix sources, extensions often won't detect Termux or simply won't work.
If you already have Termux from the Play Store and want to switch to F-Droid, the recommended option is First uninstall the previous version and then install both Termux and its plugins from F-Droid, all from the same site.
Configure the basic environment: update and storage permissions
Once Termux is installed, the first step is to prepare it minimally to work with scripts and device files. There are two key steps to do this: update packages and integrate Android storage.
Updating your Termux distribution is as simple as using the package manager. Instead of using directly aptTermux offers the command pkgwhich simplifies the process and takes care of doing apt update when it touches.
The second step is to grant access to the mobile device's storage. By default, Termux only sees its own directory. $ HOMEwhich is isolated from the rest of Android. If you want to read and write to the internal memory or the SD card, you must run:
termux-setup-storage
This command will ask for permissions and create a directory $HOME/storage with links to downloads, documents, picturesetc. In this way, your scripts will be able to Read and copy files to and from the Android user area without having to juggle.
If what you want is, for example, install an APK and copy some files When accessing internal storage from a script, it's essential to have granted these permissions beforehand. Otherwise, you'll almost certainly encounter the dreaded "Permission denied" error.
Understanding the routing structure in Termux and the shebang concept
Termux does not use exactly the same hierarchy as a standard Linux distro. Paths like /bin, /usr, or /etc are not where you expect them to be., and that affects the shebangs of scripts (the line that starts with #! indicating the interpreter).
In many guides or projects (such as Instagram bots like InstaPy) you will see scripts with headers like this #!/bin/sh o #!/usr/bin/env pythonIn older versions of Termux, it was necessary to "fix" those paths with a utility called termux-fix-shebangbecause the binaries were not on the typical routes.
Recent versions include the package termux-exec, which is responsible for correctly interpret standard shebangsThanks to this, most scripts that would expect a classic Unix environment work without any modifications. Even so, if a script fails to run, it's worth checking the following:
- Let the shebang point to an interpreter who actually exists at Termux.
- Ensure the script has execution permissions with
chmod +x. - That you are using the correct path when running it (for example
./install.sho~/script.sh).
If you're someone who likes to have everything "tidy," you can create a classic directory structure in Termux (as / usr / bin) using specific commands that generate symbolic links and standard paths. It is not mandatory, but it sometimes makes it easier to reuse legacy scripts.
Creating, granting permissions, and running a .sh script in Termux
Let's get down to business: how do you create and run a simple .sh script in Termux? The basic flow is always the same: Write the script, save it, grant permissions, and run it.You can apply it to both your own script and, for example, the classic one. install.sh of projects like InstaPy Quickstart.
To create a script you can use nano, vim, emacs or editor you like bestIf you don't have any installed, a useful first step is:
pkg install nano
Let's suppose you want to create ~/script.shYou could do:
nano ~/script.sh
Inside the file, you write your script, for example, a very simple one that records the execution date:
#!/bin/sh
echo "Encendido del dispositivo: $(date)" >> ~/registros.log
When you're finished, save it to nano with Ctrl + O, Enter and then Ctrl + XYou've created the script, but it's not yet executable. To fix this, add permissions with:
chmod +x ~/script.sh
From there you can test if everything is working by running:
~/script.sh
./script.sh (if you are in the same directory as the file)
If doing this updates ~/registros.log With the date and time, you have confirmation that The .sh script works correctlyThis same recipe applies when trying to run a install.sh that you download from GitHub: make sure it has execute permissions and that you call it with the correct path.
Fixing the "permission denied" error when running .sh scripts
One of the most common headaches when someone tries to install an APK or move files using a .sh file on Android is that Everything seems correct, but the terminal responds with "Permission denied".In Termux, this problem usually has several typical causes.
The first and most obvious is that The script lacks execution permissionsEven if you're wearing the perfect shebang, without a chmod +x archivo.sh There's nothing to be done. It's a classic oversight that should always be checked.
Another common cause is that The script attempts to write to system paths where Android does not allow it.Especially without root access. Forget about freely manipulating system directories; focus on user paths (like the ones exposed). $HOME/storage) or in what the app itself can manage.
It may also happen that You are launching the commands from a terminal emulator other than TermuxWithout the proper permissions and environment, many other Android terminal emulators suffer from permission issues and don't integrate storage or APIs as well, causing the same commands that work on a real Linux system to fail there.
In the specific case of someone trying to install InstaPy Quickstart on Android, the critical point is that Termux must have all dependencies available (Python, pip, necessary libraries) and the script install.sh It must run within Termux, not in some random app. If you run it correctly and it still fails, check the installation paths, the shebang, and the permissions of the target directories.
Automatically run .sh scripts when Android starts with Termux:Boot
Once the basics are mastered, many people want to go a step further and make Certain scripts run automatically when the device is turned on.That's what the add-on is for. Termux:Boot.
Termux:Boot is an app that integrates with Termux and It launches all the .sh scripts it finds in a special directory. when the phone finishes booting. It's ideal, for example, for starting services like MySQL, small daemons, logging tasks, or any automation you need at startup.
You can get Termux:Boot from Google Play (paid in some countries) or from F-Droid, where it's available for free. But remember the golden rule: Termux and Termux:Boot must come from the same source. so that their signatures match. If you use F-Droid for Termux, also use F-Droid for Termux:Boot.
After installing Termux:Boot, it is usually enough by opening the app once so that it registers as a receiver of the boot event. It doesn't need extensive configuration; its magic happens in the background by reading the scripts you place in the appropriate directory.
Script path at startup: ~/.termux/boot and practical example
The Termux:Boot mechanism is simple: Any .sh script you place inside ~/.termux/boot/ will run at device startupThe folder does not exist by default, so you will have to create it yourself.
To do this in Termux, run:
mkdir -p ~/.termux/boot/
From there, you can directly create your scripts within that path or copy the ones you already have. Following the previous example, if we had created ~/script.shWe could copy it like this:
cp ~/script.sh ~/.termux/boot/script.sh
As long as the file has execution permissions (chmod +x ~/.termux/boot/script.sh), Termux:Boot will launch it on every boot. That script may contain any valid command for bash/sh, from writing to a log to starting a database service with something like:
mysqld_safe -u root &
If you want to make sure everything is set up correctly, it's a good idea reopen the Termux:Boot app Wait a few seconds, close, and then restart the device. When it powers on, check the contents of your log file or the status of the services you tried to start from the script.
Using cron and other automations with Termux
In addition to starting the system, you can also Schedule recurring tasks with cron in TermuxTo do this, you need to install the corresponding package and configure your crontabs just like you would on any Linux system.
Once installed, you use crontab -e To edit the cron table and add entries. For example, you could configure a job to run every minute and create or update a specific directory, or to launch a .sh script at a certain interval.
The operation of cron in Termux is very similar to that of a standard Linux system, but it has one important limitation: If Android kills the Termux app in the backgroundThe tasks might stop running. As long as the system respects the process, cron works very well, but this is something to keep in mind on phones with aggressive battery-saving policies.
If you're unsure about cron syntax (the minute, hour, day, etc. expressions), you can use resources such as crontab.guru, which help you write the correct programming visually.
Integrating Termux with Android: Termux: API and scripts when sharing
One of Termux's great strengths is that it doesn't just stay within an isolated terminal: with the add-on Termux:API You can access many Android hardware features and combine them with your .sh scripts, and also with tools like SL4A on Android.
To use it, first install the Termux:API app from F-Droid or the Play Store (following the same source policy as with the rest of the plugins) and then install the package in the terminal termux-apiFrom there, your scripts can call commands like:
- termux-notification to show notifications on Android.
- termux-dialog to open dialog boxes and request data from the user.
- termux-toast to display short messages on screen.
- termux-tts-speak to use Google's TTS (text to speech).
- termux-media-player to play audio/video.
- termux-microphone-record to record audio from the microphone.
- Commands for clipboard, location, camera, etc.
In addition, Termux can capturing certain Android "intents"This allows scripts to be run automatically when sharing files or URLs from other apps.
For example, if you share a link from YouTube to Termux, the script will run. ~/bin/termux-url-opener receiving the URL in the variable $1. You only have to:
- Create the directory ~/bin if it does not exist.
- Create the file termux-url-opener inside him.
- Give execution permissions with
chmod +x ~/bin/termux-url-opener.
Within that script you can, for example, have the video downloaded with youtube-dl or similar using the URL that arrives in $1or save the link to a list to read later.
Something similar happens with termux-file-editorWhen you share a file with Termux, that handler is launched. You can configure it to open your favorite editor by creating a symbolic link like this:
ln -s $PREFIX/bin/nvim ~/bin/termux-file-editor
Or write your own script termux-file-editor (With nano(mark it as executable, etc.) to process the file the way you want. It's a very powerful way to chaining actions between Android and your .sh scripts.
Run scripts from widgets and shortcuts: Termux:Widget
If you like comfort, there's another particularly useful accessory: Termux:WidgetThis plugin allows you to create shortcuts on the home screen for run scripts directly from a widgetwithout manually opening the terminal each time.
For it to work, you must place your scripts in specific paths:
- ~/.shortcuts/ for scripts that will appear in the widget.
- ~/.shortcuts/tasks/ for specific tasks managed by the plugin.
- ~/.shortcuts/icons/ for the PNG icons that will be displayed with each script.
The icon file name must match the script name by adding . Png, for example script.sh.pngOn a typical Full HD screen, a size of 96 × 96 px It usually works well, although for larger screens it may be advisable to increase to 144px or 196px.
Simply by placing the script in ~/.shortcuts/, give it execution permissions and add the Termux widget to your launcher, You'll be able to launch that .sh file with a simple tap.Perfect for tasks you repeat often: backups, syncs, voice notes, etc.
Other advanced tools and use cases with Termux
Beyond running individual scripts, Termux allows you to have a surprisingly complete work environment On Android, you can install interpreters for languages ​​like Python, Ruby, Perl, Node.js, or Rust and use them with your .sh scripts to automate more complex tasks.
You can also ride complete development environments with git, gcc, make, Neovim, Emacs, etc., and even web servers, database servers, or SSH services. Many users keep their dotfiles in a git repository to clone their configuration directly into Termux and feel "at home" on any Android device.
If you use password managers like passYou can install them along with gnupg and sync your passwords via Git, allowing you to have them available on your mobile device as well. Even tools like and seafood heaven (a very user-friendly shell) and modern utilities such as zoxide, starship, ripgrep, lsd, bat or atuin They integrate seamlessly.
For those coming from a desktop background, the idea of ​​having an SSH server or a web server running on the phone It's not crazy at all with Termux. You can start it with a simple .sh script, link it to Termux:Boot or a widget, and manage it like a small portable server.
Support for graphical interfaces via X11 and VNC It's also available, although it requires more advanced setup; if you're interested, check it out. How to emulate and run Linux on AndroidEven so, it demonstrates the extent to which Termux surpasses the simple idea of ​​a "terminal emulator" and becomes a small Linux distro within Android.
With all this, Termux becomes a kind of Swiss Army knife: From installing a simple APK with a .sh script to automating complex tasks by combining Android APIs, cron, system startup, and widgetsYou can put practically anything you can imagine doing in a Linux terminal in your pocket.
