IEEE Bash Scripting


           

Compiled vs Interpreted Example

program.c program

#include <stdio.h>
  int main() {
  int a = 36;
  int b = 6;
  printf("The answer to life, the universe,\
  and everything: %d\n", a+b);
  return 0;
  }
                
$ gcc program.c -o program

program.py

a = 36;
  b = 6;
  print("The answer to life, the universe,\
   and everything: {}".format(a+b))
$ python everything.py
  The answer to life, the universe, and everything: 42

Compiled vs Interpreted Example

program.c program

#include <stdio.h>
  int main() {
  int a = 36;
  int b = 6;
  printf("The answer to life, the universe,\
  and everything: %d\n", a+b);
  return 0;
  }
                
$ gcc program.c -o program
$ ./program
We know the answer is 42, but what is the question?

program.py

a = 36;
  b = 6;
  print("The answer to life, the universe,\
   and everything: {}".format(a+b))
                
$ python everything.py
  The answer to life, the universe, and everything: 42
                

TODO: Show how there exists a python shell

TODO: Entering commands into terminal example example

How programs can be called: firefox, steam, discord, grep

TODO: Go list what are some commands line by line

cd ls echo/printf

TODO: Go list what are some commands line by line CONTD.

cat, other commands we might use in the scripts

TODO: Explain how command shells there are: zsh on mac, Powershell and Command Line Prompt on Windows, and Bash, then more alternatives

POSIX IEEE 1003.1 (2017)

TODO: Funny Yash shell

Control Logic

If Statement:

if COMMAND; then
  # Insert more commands here
fi

Control Logic

If Statement:

if COMMAND; then
  # Insert more commands here
fi

if COMMAND; then
  # Insert more commands here
else
  # Do otherwise
fi

Control Logic

If Statement:

if COMMAND; then
  # Insert more commands here
fi

if COMMAND; then
  # Insert more commands here
else
  # Do otherwise
fi

if [[ 2 -eq 2 ]]; then
  # Insert more commands here
else
  # Do otherwise
fi

TODO on these things

- Piping - If Statement: - && and || - For loops: - How the scripts actually work - functions, associative arrays, string substition, etc. - Look at a good cheatsheet

TODO: Give good resources on bash cheatsheets: https://devhints.io/bash

TODO: mild script example 1

TODO: mild script example 2

TODO: mild script example 3

TODO: rclone

TODO: httpd servers

TODO: wget

TODO: combining wget and http to mirror sites

Get every Canvas file from your course!

#!/usr/bin/env bash

COURSE_ID="123456"
API_TOKEN="12345~..."

mkdir -p files/

FILES=$(
	curl
	-X GET
	-H "Authorization: Bearer $API_TOKEN" \
		https://canvas.ucsd.edu/api/v1/courses/$COURSE_ID/files |
		jq -r '.[] | "\(.filename),\(.url)"'
)

echo "$FILES" | while IFS= read -r line; do
	FILENAME=$(echo $line | awk -F',' '{print $1}')
	URL=$(echo $line | awk -F',' '{print $2}')
	echo "Downloading $FILENAME..."
	curl -s "$URL" -o "$FILENAME"
	mv "$FILENAME" "files/$FILENAME"
done

echo "Done! All your files are in the 'files/' directory."

TODO: Plug in how bash is essential to supercomputing

TODO: Plug in SCC Apps and also our website

TODO: Thank you Slide

WARNING: Slides after this are just for debugging and messing with layouts,css,js,etc.

Trying to braek the bounds of the perhaps margin on this thing. They contain the maximum size of content for slides.

Example Script

#!/bin/bash
# Descr: Bash Script for Bash Workshop
printf "Hi, how are you doing?\n"

firefox

wget -k -m -r https://ieeeucsd.org/
            
#!/bin/bash
# Descr: Bash Script for Bash Workshop
printf "Hi, how are you doing?\n"

firefox

wget -k -m -r https://ieeeucsd.org/
            

HStack Example

One

Two

Three

One

Two

Three