Source code:

#!/usr/bin/env bash

# runasm - Assemble, link, and run multiple assembly files, then delete them.
if [[ $# -eq 0 ]]; then
    echo "Usage: runasm  [ ...]"
    echo "  - Assemble, link, and run multiple assembly files, then delete them."
    echo "  - Name of executable is the name of the first file without extension."
    exit 1
fi

object_files=()
executable_file=${1%.*}

for assembly_file in "$@"; do
    # Avengers, assemble!
    object_file="${assembly_file%.*}.o"
    as "${assembly_file}" -o "${object_file}"
    if [[ $? -ne 0 ]]; then
        exit 1
    fi
    object_files+=("${object_file}")
done

# Link
ld "${object_files[@]}" -o "${executable_file}"
if [[ $? -ne 0 ]]; then
    exit 1
fi

# Run, remove created files, and return exit code
./"${executable_file}"
exit_code=$?
rm "${object_files[@]}" "${executable_file}" > /dev/null 2>&1
exit "${exit_code}"
  • @jsdz@lemmy.ml
    link
    fedilink
    568 months ago

    I have two reactions: 1. The headline is rather silly. 2. There’s no way this little script, although it might conceivably be useful to someone, needs to be a youtube video.

    • StarDreamer
      link
      fedilink
      English
      68 months ago

      I mean they’re not wrong…

      This is why my next book will be titled “how to cook dinner without a compiler, GCC 4 to GCC 11 compatible!”

  • @OmnipotentEntity@beehaw.org
    link
    fedilink
    68 months ago

    Putting aside the misleading title…

    Because this writes to and then runs an executable file with a known name, this script should never be used on a multiuser system in a directory where another user has write permissions. It is vulnerable to a timing attack where the attacker copies an executable they want run with your permissions between this script creating the file and running it.

  • Oliver Lowe
    link
    38 months ago

    I’m still super confused by this user’s posts lol. I get that (some? most?) of it is satire… but then why all social media engagement farming hashtag nonsense? Or is this all part of the satire…?