Getting Started with Bash Scripts

Length: 00:09:29

Lesson Summary:

In this lesson we discuss some of the basic components of a Bash script, and how we can use them with Azure CLI.

This is an introductory lesson and is intended to provide a basic awareness of the benefits of scripting. It also explains how to build and execute a script.

Helpful tips

  • It is common to use the extension .sh for Bash scripts you are creating, but it's not entirely necessary.
  • You may prefer to create a script locally and then upload to your Cloud Shell using the Upload feature in the Cloud Shell toolbar.

New and helpful commands:

  • Opening or creating a file with VI: vi filename
  • Closing a file in VI: Press ESC > q > enter (separately, in this order)
  • Saving a file in VI: Press ESC > w > enter (separately, in this order)
  • Exiting without saving: Press ESC > w! > enter (separately, this order)
  • Making a file executable: chmod +x file
  • Listing all files: ls -la or ls
  • Executing a file: /path/to/file.sh

All commands used if you wish to follow along:

vi script1.sh
chmod +x script1.sh
ls -la
clear
./script1.sh

script1.sh:

#!/bin/bash

timeStamp=$(date)

echo "Hello awesome students!"
echo "The time is: ${timeStamp}"
echo "Let's take a look at our resource groups"

az group list -o table

This lesson is only available to Linux Academy members.

Sign Up To View This Lesson

Or Log In

Looking For Team Training?

Learn More