CSI6203 Workshop 4

CSI6203 Workshop 4


To introduce you to snippets and additional bash features.

Task 1: Command Redirection

  1. Let’s use some redirection to automate the use of our “foldercopier.sh” from last week.
  2. Thanks to the < operator, we can automate the user input from the “read” commands.
  3. First, use the bash command line to navigate to the CSI6203 folder.
  4. Then run the following command to create a new file for automating the script

foldierCopier.sh to be copied across

echo -e “../week3/ ../week4” > userInput.txt

  • Then run the foldercopier.sh script with redirection instead of user input.

./portfolio/week3/folderCopier.sh < userInput.txt

  • This should automatically use the “userInput.txt” as input instead of needing to type it manually. Leaving your folder structure looking like this:

Don’t cheat and use the GUI!

Task 2: Making Snippets

To make our scripting experience easier, we should make a snippet.

Let’s start with a simple shebang example.

  1. In VSCode, Navigate to File->Preferences->UserSnippets
  2. Choose the “shellscript.json” file from the UserSnippets menu.
  3. Add the following snippet to the file:

“add a shebang”:

        “prefix”: “#!”,

        “body”: [



        “description”: “Add shebang to script”


Now the shebang should be able to be inserted just by starting to type “#!”

Task 3: Making your own snippets

  1. Write a snippet that will automatically insert variables for shell colours.
  2. You can find an example of these kinds of colour variables in this week’s vignette on “More Scripting Syntax”

Here is a table of colour codes that you can use when developing this snippet:

Colour Code
Black \033[30m
Red \033[31m
Green \033[32m
Brown \033[33m
Blue \033[34m
Purple \033[35m
Cyan \033[36m
Grey \033[37m
  • When you’re done, Save a copy of your “shellscript.json” in the “week 4” folder

Task 4: A simple calculator

Write a script that uses conditional logic and arithmetic expressions to make a simple calculator.

The calculator should allow the user to do:

  1. addition,
  2. subtraction,
  3. multiplication and
  4. division of integers.
  1. Addition operations should appear in Blue
  2. Subtraction operations should appear in Green
  3. Multiplication operations should appear in Red
  4. Division operations should appear in Purple

How the user interacts with this script is up to you!

Task 5: git and github

  1. Now that we have the week 4 scripts completed for our portfolio, you can commit your changes to the git repository.
  2. Make sure to add all of the new work to source control.

Git hub not synchronizing

If having issue with GitHub not synchronising during push from local to remote do the following:

  1. Remove the .git folder from your local folder structure (.git)
    1. sudo rm -r .git
  2. git init
  3. git add .
  4. git config … as per previous instructions
  5. Go into Visual Studio Code
    1. code . (from within the terminal)
  6. Open the parent folder CSI6203
  8. git remote add
    1. Add your remote .git path
    1. When asked to stage all changes select ‘ALWAYS’
    1. When prompted for the user name ‘type in your username’ GitHub
    1. When prompted for the password ‘type in your password’ for the GitHub