CompSci Blogs

August 2023 to June 2024

View the Project on GitHub sfremy/csablog

31 August 2023

Linux Shell & Bash Usage

by

How to Use Bash

Overview

Bash is a shell and command language used by most Linux operating systems. It is a command-line interface but can also read and execute commands from a file, as is being done here.

Setup

To make a Bash script in VSCode's Jupyter notebook implementation, use 'Shell Script' as the cell type and open with "%%script bash".

%%script bash

You can treat the cell as a terminal and input your command list. When run, it will treat the commands the same as a normal Linux shell.

Hack

Part 1

"Come up with your own student view of this procedure to show your tools are installed. It is best that you keep the few things you understand, add things later as you start to understand them." (I understand this to mean an installation/version check on the tools.)

Let's check the installation and version status of Python, Ruby, and Jupyter, and also check to see whether the student directory exists.

%%script bash

echo "Python version check"
which python
python --version
echo ""

echo "Ruby version check"
which ruby
ruby -v
echo ""

echo "Jupyter version check"
which jupyter
jupyter --version
echo ""

echo "Try to navigate to VSCode directory and display its contents."
cd ~
cd vscode
ls
echo ""

Part 2

"Name and create blog notes on some Linux commands you will use frequently."

Some of the most commonly used Bash commands are:

Part 3

"Is there anything we use to verify tools we installed? Review versions?"

The command --version can be used to retrieve the version numbers of tools. The command which can be used to find the filepath of whatever it is given, or returns /dev/null if it does not exist.

Part 4

"How would you update a repository? Use the git command line?"

To update a Github repository, do this:

%%script bash

# Navigate to your desired directory
$ git clone https://github.com/sfremy/csablog.git

This should replace the file specified in the clone command with the latest version linked.

tags: