#!/usr/bin/env sh # This magical spell reveals the maximum length of a list of strings. # Usage: cast_max_length string1 string2 ... # Define the function to calculate the maximum length of the given strings max_length() { # Initialize the maximum length to 0 max_length=0 # Loop through the arguments and calculate the maximum length for string in "$@"; do length=${#string} if [ $length -gt $max_length ]; then max_length=$length fi done # Output the maximum length echo "Maximum length: $max_length" } # Check if the script is being called from another script if [ "${BASH_SOURCE[0]}" = "$0" ]; then # If not, call the function and pass it the command line arguments max_length "$@" fi