Follow ZDNET: Add america arsenic a preferred source connected Google.
ZDNET's cardinal takeaways
- Enabling Linux enactment connected Android has respective benefits.
- With this feature, you tin make and tally bash scripts.
- This is precise useful for learning the ins and outs of scripts.
Bash scripts are a large mode to automate each sorts of repetitive tasks -- you tin tally backups, wide impermanent files/logs, rename oregon batch-rename files, instal oregon update software, and overmuch more.
Although penning specified scripts isn't astir arsenic hard arsenic you mightiness think, it does instrumentality immoderate clip to larn the ins and outs of bash scripting.
Also: 6 hidden Android features that are earnestly utile (and however they made my beingness easier)
Good news: If you person an Android device, you tin alteration the Linux terminal, which means you tin make oregon signifier your bash scripting connected the go.
If that sounds similar thing you'd similar to effort out, support speechmaking to larn much astir penning Linux bash scripts connected Android.
How to constitute Linux bash scripts connected your Android
What you'll need: The lone happening you'll request for this is an Android instrumentality with the Linux situation enabled. You tin find retired however to bash this successful my article, "How to usage the caller Linux terminal connected your Android instrumentality - it's easy."
With the Linux terminal ready, let's commencement our bash publication journey.
Installing nano
Here are the steps for installing the nano editor, which you'll usage to create/modify your bash scripts.
Open your App Drawer and hunt for the launcher labeled "Terminal."
Before you tin instal nano, you person to archetypal update Linux. To bash this, benignant the pursuing bid successful the terminal:
sudo apt update
After that bid completes, upgrade with:
sudo apt upgrade
You tin present instal the nano exertion with the command:
sudo apt instal nano
After that, you're acceptable to go.
Creating your archetypal script
Creating a basal Linux bash publication is really rather easy. Let's make a publication that simply prints "Hello, ZDNET" successful the terminal.
To bash this, contented the command:
nano hello.sh
You should present spot an bare record acceptable for content. The archetypal enactment of immoderate Bash publication is:
#!bin / bash
Note: Make definite to region the spaces connected either broadside of the / character.
Also: How to wide your Android telephone cache (and hitch retired lag for good)
What the supra enactment does is guarantee the publication is tally via the Bash shell.
The adjacent enactment volition be:
echo "Hello, ZDNET"
Save and adjacent the record by tapping Ctrl and past pat x connected the keyboard. When prompted, benignant y, then pat Enter.
Next, you request to springiness the publication executable support with the command:
chmod u+x hello.sh
Let's tally our publication and spot what happens, which is done with:
./hello.sh
You should spot "Hello, ZDNET" successful the output.
Let's constitute a much utile script. We'll make a publication that removes files from the /tmp directory. Although you should truly fto the strategy grip this, the publication is simply a bully intro for those caller to the task.
Create the record with:
nano delete.sh
As usual, the archetypal enactment is the aforesaid arsenic it was successful the supra script. The main enactment of the publication is then:
rm -rf /tmp/*.*
Save and adjacent the file. Give the caller publication executable support with:
chmod u+x delete.sh
You tin present tally this record with:
sudo ./delete.sh
You person to usage sudo due to the fact that changing thing wrong /tmp requires admin privileges. If you look successful /tmp, you'll find it's present empty.
Also: The archetypal 8 Linux commands each caller idiosyncratic should learn
Remember, though the supra method of removing files isn't the mean route, it's a bully mode to learn. Let's make a backup with a publication that requires idiosyncratic input.
Create a caller record named input.sh. In that file, spot the aforesaid starting enactment astatine the apical and past adhd the following:
read -p "Enter your name: " name
echo "Hello, $name! Welcome to ZDNET."
Save and adjacent the file. After giving the caller publication executable permissions (chmod u+x input.sh), tally the bid (./input.sh), and you'll spot the output with the sanction you typed.
Keep this successful mind
Remember, you're utilizing Linux connected Android, truthful I wouldn't see this a viable mode to negociate your Android device. However, it's a large mode to larn however to constitute bash scripts for Linux.
However, I'd similar to adhd an asterisk to the supra caveat. You tin entree immoderate of the Android directory structure, specifically, /mnt/shared. In that directory, you'll find sub-directories of immoderate of the apps you've installed connected your devices. For example, 1 directory is /mnt/shared/Pictures.
Let's accidental you privation to make a publication to bare that directory. That publication starts with the aforesaid archetypal enactment arsenic always, and adds the following:
sudo rm /mnt/shared/Pictures/*.*
Also: My 8 must-use Linux commands, and however they tin marque your beingness easier
So, yes, creating Bash scripts connected Android could beryllium utile (other than for education). However, delight bash beryllium cautious erstwhile utilizing Bash scripts successful the Android directory. It's good to usage them successful the Linux environment, due to the fact that you tin ever disable Linux enactment and re-enable it to commencement each over. If you messed up the Android record structure, you mightiness person to bash a mill reset. You don't privation that.

2 hours ago
3







English (US) ·