How to create a Bash Script in Ubuntu?

How to create a Bash Script in Ubuntu?

1. Open the terminal window:
The first thing you Must Do is open the terminal window, which can be found within your desktop menu.

2. Create the New File:
Our script file will be called: update_upgrade_autoremove_clean_and_clear.sh.

Create the file with the command:
nano update_upgrade_autoremove_clean_and_clear.sh

3. Create the Bash Script:
The first line in every bash script is:
#!/bin/bash

The second line of the script is the Hello, World! portion. First, we’ll add a comment that indicates what the next command does, which might look like this:
# My Hello, World! script

Finally, the command for the bash script uses the echo command like so:
echo “Hello, World!”

Put it all together and it looks like this:
#!/bin/bash
# My Hello, World! script
echo “Hello, World!”

sudo apt update
sudo apt upgrade
sudo apt-get dist-upgrade
sudo apt-get autoremove
sudo apt-get -y clean
sudo apt-get -y autoclean
clear

Save and Close the file with the Ctrl+X keyboard shortcut.

4. Give the script executable permissions:
Before the script can be run, it must have executable permissions. To do that, issue the command:
chmod +x update_upgrade_autoremove_clean_and_clear.sh

5. Run the command:
To run your bash script, issue the command:
./update_upgrade_autoremove_clean_and_clear.sh

The output of the command should be “Hello, World!”…
(Discover the basics of bash scripting and learn how to write a bash script.)

===

All Updates:

1. sudo apt update

2. sudo apt upgrade

3. sudo apt-get dist-upgrade

4. sudo apt-get autoremove

5. sudo apt-get -y clean

6. sudo apt-get -y autoclean

7. clear

===

Discover more Lessons: Courses – Training and Education courses (All types of Courses)

Shopping Basket
Scroll to Top
Verified by MonsterInsights