Skip to content

Session 5 notes

BusyBox

  • busybox-static commands

CATDOG

#!/bin/bash
  • #! indicates the start of the shebang
  • /bin/bash specifies the Bash interpreter
printf '%s\n' '#!/bin/sh' 'echo "voff"' > dog
echo "$(< /home/inmate_hanndoddi_0xdec0de/day1.txt)"
while IFS= read -r line; do echo "$line"; done < /home/inmate_hanndoddi_0xdec0de/day1.txt
  • cat linux alternative ways to look at files cat
  • mapfile -t lines < file.txt: Reads a whole file directly into an array.
  • $(<file.txt): Reads file contents directly into a variable or string output.
  • while IFS= read -r line; do ... done < file.txt: Standard, memory-safe loop to process text line by line.
  • cat linux alterniti ways to look at files bash script
  • File Handling in Bash Scripting

bash

Bash-Cheat-Sheet

Bash scripting cheatsheet

  • sh command linux
  • sh binary how to see the available commands

Custom Shell Scripting

- printf command in Linux with Examples

cat script

#!/bin/bash

# Check if a filename was provided
if [ -z "$1" ]; then
    echo "Usage: $0 <filename>"
    exit 1
fi

FILE=$1

# Verify that the file exists before running cat
if [ -f "$FILE" ]; then
    echo "--- Displaying content of $FILE ---"
    cat -n "$FILE"   # The -n flag adds line numbers
else
    echo "Error: File '$FILE' does not exist."
    exit 1
fi
printf '%s\n' '#!/bin/sh' 'if [ -z "$1" ]; then echo "Usage: $0 <filename>"; exit 1; fi' 'if [ -f "$1" ]; then echo "--- Displaying $1 ---"; while IFS= read -r line; do echo "$line"; done < "$1"; else echo "Error: File does not exist."; exit 1; fi' > /bin/dog

alias

alias mycat='while IFS= read -r line; do echo "$line"; done <'

chroot command

chroot command in Linux with examples

Kernel

Searchable Linux Syscall Table