server_photo_s85js/print_function.sh
2026-08-11 08:45:04 +02:00

40 lines
649 B
Bash
Executable file

#!/bin/bash
# Estrae e stampa una funzione da un file.
#
# UTILIZZO:
# ./print_function.sh <nome_funzione> <file>
#
# ESEMPIO:
# ./print_function.sh myFunction myfile
#
# La funzione viene stampata sullo standard output.
if [ "$#" -ne 2 ]; then
echo "Uso: $0 <nome_funzione> <file>"
exit 1
fi
FUNCTION="$1"
FILE="$2"
awk -v func="$FUNCTION" '
/^[[:space:]]*function[[:space:]]+/ {
if ($0 ~ "^[[:space:]]*function[[:space:]]+" func "[[:space:]]*\\{") {
found=1
braces=0
}
}
found {
print
braces += gsub(/\{/, "{")
braces -= gsub(/\}/, "}")
if (braces == 0) {
exit
}
}
' "$FILE"