r/bashscripts • • Nov 27 '22

What does this script do

I need to explain what this script does for a question on my classwork but my teacher isn't satisfied with my answer. Can anyone provide some insight into what exactly is happening with this script?

#!/bin/bash

if [ -z “$1” -o -r “$2” ]; then

echo “Usage: myscript [file] [size]”

exit 255

fi

SIZE=`ls -l $1 | awk ‘{print $5}’`

if [ $2 -gt $SIZE ]; then

echo “Your size must be smaller than the file size!”

exit 254

fi

CHUNK=$2

TOTAL=0

PASS=0

while [ $TOTAL -lt $SIZE ]; do

PASS=$((PASS + 1))

echo “Creating $1.$PASS …”

dd conv=noerror if=$1 of=$1.$PASS bs=$CHUNK skip=$((PASS – 1)) \

count=1 2>/dev/null

TOTAL=$((TOTAL + CHUNK))

done

echo “Created $PASS files out of $1.”

2 Upvotes

2 comments sorted by