• Home
  • About Us
  • Privacy Policy
  • Contact Us
  • Disclaimer
  • Terms & Conditions
Journal Official
Advertisement
  • Home
  • Tech
    • All
    • Apps
    • Gadgets
    Google’s CFO just got promoted

    Google’s CFO just got promoted

    How Google’s latest AI model is generating music from your brain activity

    How Google’s latest AI model is generating music from your brain activity

    Easy Rider to Midnight Run, The Greatest Roadtrips Movies of All Time

    Easy Rider to Midnight Run, The Greatest Roadtrips Movies of All Time

    Three new Starfield animated shorts offer more glimpses of Bethesda’s new universe

    Three new Starfield animated shorts offer more glimpses of Bethesda’s new universe

    Some top AMD chips have a huge security flaw

    Some top AMD chips have a huge security flaw

    What is a Linux Bash Script and How Do You Build One?

    What is a Linux Bash Script and How Do You Build One?

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Entertainment
  • Sports
  • CryptoCurrency
  • Business
  • Health and Lifestyle
    • All
    • Food
    World IVF Day: Infertility is a silent epidemic – why is it important to tackle fertility problems?  experts tell

    World IVF Day: Infertility is a silent epidemic – why is it important to tackle fertility problems? experts tell

    What is ‘duck walk’ in old age?  Expert shares tips on maintaining normal mobility

    What is ‘duck walk’ in old age? Expert shares tips on maintaining normal mobility

    Radiohead brands portfolio expands with the launch of Hustle™ energy drink.  Unveiled through new campaign “Dreams are free, #HustleModeOn for everything else – Food Marketing Technology”

    Radiohead brands portfolio expands with the launch of Hustle™ energy drink. Unveiled through new campaign “Dreams are free, #HustleModeOn for everything else – Food Marketing Technology”

    From Chris Gayle to Virat Kohli: Most runs scored by players in India vs West Indies ODI series

    From Chris Gayle to Virat Kohli: Most runs scored by players in India vs West Indies ODI series

    Infertility Treatment: How Ayurveda Can Help Increase Fertility?  experts tell

    Infertility Treatment: How Ayurveda Can Help Increase Fertility? experts tell

    Ishant Sharma opens up about the truth behind Zaheer Khan’s Test retirement and the allegations against Virat Kohli

    Ishant Sharma opens up about the truth behind Zaheer Khan’s Test retirement and the allegations against Virat Kohli

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
No Result
View All Result
  • Home
  • Tech
    • All
    • Apps
    • Gadgets
    Google’s CFO just got promoted

    Google’s CFO just got promoted

    How Google’s latest AI model is generating music from your brain activity

    How Google’s latest AI model is generating music from your brain activity

    Easy Rider to Midnight Run, The Greatest Roadtrips Movies of All Time

    Easy Rider to Midnight Run, The Greatest Roadtrips Movies of All Time

    Three new Starfield animated shorts offer more glimpses of Bethesda’s new universe

    Three new Starfield animated shorts offer more glimpses of Bethesda’s new universe

    Some top AMD chips have a huge security flaw

    Some top AMD chips have a huge security flaw

    What is a Linux Bash Script and How Do You Build One?

    What is a Linux Bash Script and How Do You Build One?

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Entertainment
  • Sports
  • CryptoCurrency
  • Business
  • Health and Lifestyle
    • All
    • Food
    World IVF Day: Infertility is a silent epidemic – why is it important to tackle fertility problems?  experts tell

    World IVF Day: Infertility is a silent epidemic – why is it important to tackle fertility problems? experts tell

    What is ‘duck walk’ in old age?  Expert shares tips on maintaining normal mobility

    What is ‘duck walk’ in old age? Expert shares tips on maintaining normal mobility

    Radiohead brands portfolio expands with the launch of Hustle™ energy drink.  Unveiled through new campaign “Dreams are free, #HustleModeOn for everything else – Food Marketing Technology”

    Radiohead brands portfolio expands with the launch of Hustle™ energy drink. Unveiled through new campaign “Dreams are free, #HustleModeOn for everything else – Food Marketing Technology”

    From Chris Gayle to Virat Kohli: Most runs scored by players in India vs West Indies ODI series

    From Chris Gayle to Virat Kohli: Most runs scored by players in India vs West Indies ODI series

    Infertility Treatment: How Ayurveda Can Help Increase Fertility?  experts tell

    Infertility Treatment: How Ayurveda Can Help Increase Fertility? experts tell

    Ishant Sharma opens up about the truth behind Zaheer Khan’s Test retirement and the allegations against Virat Kohli

    Ishant Sharma opens up about the truth behind Zaheer Khan’s Test retirement and the allegations against Virat Kohli

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
No Result
View All Result
Journal Official
No Result
View All Result
Home Tech

What is a Linux Bash Script and How Do You Build One?

admin by admin
July 25, 2023
in Tech
0
What is a Linux Bash Script and How Do You Build One?
0
SHARES
5
VIEWS
Share on FacebookShare on Twitter


Sure, bash scripts can get very complex – but at first they can be as simple as you want them to be.

degreez/Getty Images

I’ve been using Linux for a very long time, during which time I’ve done everything you can imagine with the open-source operating system. From my early days, one thing that I needed to learn was to create bash scripts. When I first started using Linux, I had a 33.6k modem that refused to stay online. To get around that problem, I had to create a bash script that would monitor my connectivity; If the script detects that I am offline, it will reconnect me.

Thankfully, I no longer have to resort to such tricks. In fact, Linux has become so user-friendly that I rarely have to bother with bash scripts. Still, it’s a great feature to have handy.

Too: How to choose the right Linux desktop distribution for you

What is bash script?

Think of a Bash script as a small application you create that contains Linux commands. You can write Bash scripts to do just about anything, such as creating backups, setting variables, opening applications, navigating to specific directories, creating files, and more. Really, with just a little creativity, the sky’s the limit when it comes to Bash scripts.

But remember, bash scripts are just that…scripts. They are not GUI applications, nor a GUI application that will walk you through the process of creating a script. In other words, Bash scripts are a bit more advanced than using a word processor, web browser, or email client.

This does not mean that bash scripts are only for advanced users. Sure, bash scripts can be very complex but in the beginning they can be as simple as you want.

I’m going to create and demonstrate two different bash scripts. First, we tried the tried-and-true “Hello, World!” do. And then we’ll create a bash script that will back up a directory.

are you ready let’s go.

How to make Hello World! bash script

what you’ll need: The only thing you will need for this is a running instance of Linux. Since every distribution supports bash scripts, it doesn’t matter which one you use. Having prepared it, let’s create.

The first thing you should do is open the Terminal window, which can be found in your Desktop menu.

Our first script file will be called hello_world.sh. Create file with command:

The first line in each bash script is:

The second line of the script Hello, World! parts. First, we’ll add a comment indicating what the next command does, which might look like this:

# My Hello, World! script

Finally, for bash scripts use the command echo Order as follows:

Put it all together and it would look like this:

#!/bin/bash

# My Hello, World! script
echo "Hello, World!"

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

Before the script can be run, it must have executable permissions. To do this, issue the command:

To run your first bash script, issue the command:

The output of the command “Hello, World!” Should be

Too: The most important reason why you should use Linux at home

Backup with Bash Script

Let’s say you want to back up your Documents directory to an external drive located at /media/USER/data (where USER is your Linux username). With this backup, we are also going to set variables that will be used to add the date to the backup file name, set the destination as well as set the source. we will also use Tar command for actual backup.

The first thing to do is to create a new file with the command:

Too: best linux distros for beginners

1. Create new file

The first thing to do is to create a new file with the command:

2. Create Script

The complete script will look something like this (where USER is your Linux username):

#!/bin/bash

# set variables for data, destination, and source

BACKUPDATE=`date +%b-%d-%y` 

DESTINATION=/media/USER/data/DOCUMENTS-$BACKUPDATE.tar.gz 

SOURCEFOLDER=/home/USER/Documents 

# the backup command

tar -cpzf $DESTINATION $SOURCEFOLDER #create the backup

The destination variable not only sets the location for the backup, but it also names the backup DOCUMENTS-BACKUPDATE.tar.gz (where the BACKUPDATE script will be the date it was run). For example, if you run the backup script on July 24, 2023, the file will be named DOCUMENTS-Jul-24-23.tar.gz.

3. Give executable permissions to the script

To make it so that the script can be run, give it executable permissions with the command:

4. run the script

To run the new backup bash script, the command would be:

And that’s all it takes to create your first bash script. As I said, with a little creativity, you can do a lot with these handy little command-line applications.

Too: My idea for a great new beginner-friendly Linux distribution

Previous Post

Why is computer security advice more confusing than it should be?

Next Post

Digital Shovel unveils Nanopod, a compact and efficient bitcoin mining solution

admin

admin

Next Post
Digital Shovel unveils Nanopod, a compact and efficient bitcoin mining solution

Digital Shovel unveils Nanopod, a compact and efficient bitcoin mining solution

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Journal Official

Welcome to our News Magazine Website, your go-to source for the latest and most compelling news around the Globe. Stay informed, stay inspired, and explore the world through our comprehensive and user-friendly platform.

Follow Us

Recent posts

  • Open Access vs. Subscription: Masa Depan Aksesibilitas Jurnal Akademik
  • Strategi Memilih Jurnal yang Tepat untuk Naskah Penelitian Anda
  • Peran Jurnal Terindeks Scopus: Mengapa Penting untuk Karier Akademik
  • Etika Penulisan Ilmiah: Menghindari Plagiarisme dan Pelanggaran Kode Etik
  • Memahami Proses Peer Review: Kunci Kualitas Publikasi Ilmiah

Recent News

Open Access vs. Subscription: Masa Depan Aksesibilitas Jurnal Akademik

December 7, 2025

Strategi Memilih Jurnal yang Tepat untuk Naskah Penelitian Anda

December 7, 2025
  • Home
  • About Us
  • Privacy Policy
  • Contact Us
  • Disclaimer
  • Terms & Conditions

© 2023 Journal Official - News Magazine

No Result
View All Result
  • Disclaimer

© 2023 Journal Official - News Magazine