どうすればいいのか知りたいです。
printf "Credentials found!"
複数の資格情報が見つかった場合は一度だけ発生します。
Attempting Dictionary Attack on 192.168.91.130
Credentials Found!
Log into the telnet server by running telnet -l admin 192.168.91.130
When prompted enter the password found 'admin'
Credentials Found!
Log into the telnet server by running telnet -l sfx 192.168.91.130
When prompted enter the password found 'toor'
サイクルbash
:
for i in "${!user[@]}"; do
printf "The Username & Password is %s : %s\n\n" "${user[i]}" "${pass[i]}" >> SSH-Credentials.txt
printf "${NCB}Credentials Found!${NC}\n\n"
printf "Log into the SSH server by running ${YELLOW}ssh ${user[i]}@$ip${NC}\n\nWhen prompted enter the password found ${YELLOW}'${pass[i]}'\n"
printf "${NC}\n"
done
ベストアンサー1
$i
次のようにテストできます。
[[ "$i" -lt 1 ]] && printf "I am only printed once\n"
# OR
(( i < 1 )) && printf "I am only printed once\n"
# OR
! (( i )) && printf "I am only printed once\n"
# OR
[ "$i" -lt 1 ] && printf "I am only printed once\n"
# OR
if [[ "$i" -lt 1 ]]; then
printf "I am only printed once\n"
fi
使わないと仮定すると関連 bash 配列。
簡単に言うと:インデックスが1より小さい場合は印刷します。
また、読みやすいように行を分けてみましょう。道は広い。次のように言うこともできます。
printf '%s %s some long text' \
"$var1" "$var2"
変数に大文字を使用するのも悪い習慣です。
情報は通常、次にも印刷する必要があります。stderr
だから>&2
。
また、以下を使用してください。
prinf '%s@%s' "${user[i]}" "$ip" >&2
変える:
prinf "${user[i]}@$ip" >&2