Minutes 2026-10-29

From MTU LUG Wiki
Revision as of 23:54, 29 October 2026 by Simone (talk | contribs) (fix formatting... oopsie)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

BASH scripting by Freya!

Scripting?

    Executables are not binary

    Files start with #! (Shebang)

        Defines what binary to run the file in

        Usually /bin/bash

        Can do it with other programming langues or anything!

    Good for automation/customization

What languages?

    Any

    Can even do auto-compiled C with GCC

    Usually POSIX shell like bash

        env/bin/bash is more 'proper'

    Python

        Some scripts on your system

        Pacman

    Other shells

        fish, csh, zsh

    Shell (server) uses ZSH

    Other shells come with their own languages since that's just what they are

    All high-level

        All terminal commands are shell commands

        Pipes (part of bash language)

        Bash is part of POSIX standard so it's common on Linux/UNIX

    Bash language

        It's old

            Bounre shell

            Dates back to 60s

Use cases

    Run scripts on keybind

        You can bind any executable to a keybind

        Shortcuts (open apps) as well

    See the weather

    Interactive menus

        dmenu

        Take in a list of things and sort through them

            Useful for menus

    Repetitive tasks

    Examples:

        Transferring pictures off a camera

    Freya found a Youtube channel with a lot of cool shell scripts

        Videos edited with scripts

            Automated FFmpeg scripts

    Stringing together data

        Screenshots

            Can use slurp/grim on Wayland

        Usually scripted

            Can make it dynamic

    Process data

Basics of bash

    No built in functions

        Just call commandline applications

    Built on commands like cs, ls

    Familiar if you use CLI a lot

    Bash environment is entirely dependent on what you have installed

        JSON parsing (bad) and dependent on system packages

    Lots of cool programs to do nice things

    Environment variables

        Just a bash variable

        East to access in shell environments

        They can be complicated on other languages

    Awful syntax but decently powerful

    Good for stringing commands together with pipes

    Variables

        Assign a string to a name

        Easy to access with $

    Echo

        Print statements

    Read lines from standard input

        Grab user data

    If statements must end in fi

        Some bash statements are ended with themselves backwards

        Really weird getting arguments

            Square brackets with required spaces

            Brackets are technically a command...

    Typical programming languages things (Loops, brackets, else-if)

    Bash is a mess....

        Is this how professors feel teaching Java 8 to students?

        Or C89?

    Exit codes are like return statements to exit or give errors

Built-in things

    $n gets number 0 to 9

    $? gets error codes

        See if program failed unless it's being weird

    $@ gets arguments as arrays

    $! gets PID of background commnand

        Lets you run things asynchronously

Environment values

    Home directory

    Current username

    PATH variable

    XDG variables

        .config

        cache home

        local home

    Don't hardcode paths, use variables instead

        Better for portability

Things to remember

    Commands make life easy

    Learn to use awk, sed, and jq

        Text replacement

        JSON parsing

    Curl for internet stuff

        Or wget

    There's functions

        Make things easy for yourself

        But nobody uses them except for fork bombs

Demo time!

    Window manager mishaps...

    Example scripts

    National weather service provides prerendered radar GIFs

        Just a URL

        Always updated

        Can grab them with a script

            Downloads the gif to /tmp and plays it

        Make widgets?

        Uses just curl and mpv

    QR generator script

        Save text

        qrencode then print as image

    Scan QR from screen or camera

    All very simple, just stringing shell commands together

    Aurora script

        Shows it on a map in a window

        Free API from NOAA

        Graph of probability

    Script to add todo list item

        Doesn't work...

    Brightness control

        Drivers for brightnessctl may be broken

        Complaining about chromeOS?

        Converts value to percentage

        Hardcoded path.....

    Waybar extension

        Outputs todo status to the bar

        Just a loop to show items

Cronjobs

    Do custom things on schedules

        Weather alerts

Scripting Magnum Opus

    Grabs days of weathers

    Pulled from weather services

    Only took 2 hours

    Very easy

    It's free!

        Don't pay for weather APIs

        National weather service is free and good

        Raw model data is also free

            Even the notes they're taking

    Forecast function takes in URLs and outputs JSON

    Freya also wrote scripts for brightness and volume

    Wants to bind it to a shortcut

Inspiration

    Bread on Penguins

        Videos showing scripts

        Automated with ffmpeg

        Cool things

One more thing

    LUG lan party 3 on Sunday

End