Session 5 notes
BusyBox
- busybox-static commands
CATDOG
- #! indicates the start of the shebang
- /bin/bash specifies the Bash interpreter
- 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
- sh command linux
- sh binary how to see the available commands
Custom Shell Scripting
- printf command in Linux with Examples
- Difference between printf and echo in bash
- Linux command basics: printf
- Shell Scripting – Understanding Shebang (#!/bin/bash)
- What is the difference between #!/bin/sh and #!/bin/bash?
- printf Command in Linux with Examples - Joshua James
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
chroot command
chroot command in Linux with examples