1
0
forked from extern/SSH-Snake

Fix Snake.nocomments.sh producing an invalid script during remove_functions().

Snake.nocomments.sh incorrectly removed all leading spaces from the script,
which resulted in remove_function() thinking that an awk function's } character
was the final character of a bash function.

Fixes #1.
This commit is contained in:
Joshua Rogers 2024-01-06 01:49:55 +07:00
parent a40e8f82be
commit 7ae7ef0afe

View File

@ -138,22 +138,22 @@ function is_func_line() {
for (i in funcs) { for (i in funcs) {
if ($0 ~ "^" funcs[i] "\\(\\)") { if ($0 ~ "^" funcs[i] "\\(\\)") {
return 1 return 1
} }
} }
return 0 return 0
} }
function is_func_call() { function is_func_call() {
for (i in funcs) { for (i in funcs) {
if ($0 ~ "^[[:space:]]*" funcs[i]) { if ($0 ~ "^[[:space:]]*" funcs[i]) {
return 1 return 1
} }
} }
return 0 return 0
} }
BEGIN { BEGIN {
split(fnames, funcs, " "); split(fnames, funcs, " ");
in_func = 0 in_func = 0
} }
is_func_line() { in_func = 1; next } is_func_line() { in_func = 1; next }
/^\}/ { if (in_func) { in_func = 0; next } } /^\}/ { if (in_func) { in_func = 0; next } }
is_func_call() { next } is_func_call() { next }
@ -169,9 +169,9 @@ user = $1
for (i = 2; i <= NF; i++) { for (i = 2; i <= NF; i++) {
if ($i != "" && user != "") { if ($i != "" && user != "") {
print "\\x22" user "@" $i "\\x22" print "\\x22" user "@" $i "\\x22"
} }
} }
}' }'
done done
for ssh_dest in "${!root_ssh_hosts_dests[@]}"; do for ssh_dest in "${!root_ssh_hosts_dests[@]}"; do
printf "\\\x22%s\\\x22\n" "$ssh_dest" printf "\\\x22%s\\\x22\n" "$ssh_dest"