Q: 1
[Attacks and Exploits] A penetration tester wants to use the following Bash script to identify active servers on a network:
1 network_addr="192.168.1" 2 for h in {1..254}; do 3 ping -c 1 -W 1 $network_addr.$h > /dev/null 4 if [ $? -eq 0 ]; then 5 echo "Host $h is up" 6 else 7 echo "Host $h is down" 8 fi 9 done
Which of the following should the tester do to modify the script?
Options
Discussion
Option C, saw basically the same thing in a mock. Portability always comes up with these scripts.
C here. Using
seq instead of brace expansion makes the script work in more shells, not just Bash. I saw a similar question in practice banks, always about portability. Pretty sure that's what they want but correct me if you think otherwise.My vote is C. D is a common trap, but $h works fine and doesn't improve portability like C does for non-Bash shells.
A is wrong, C-using seq makes the script run on more shells, not just Bash. Pretty sure that's what they want here.
Nah, I think D is tempting since ${h} looks more proper in scripts, but $h works the same here so D.
Option D. I think. Using ${h} is just clearer for variable use, right?
Probably C, but does the question ask for portability across all shells or just Bash support?
C , since using seq avoids the Bash-only braces trap. D looks tempting but doesn't fix portability.
C for sure, most practice tests mention seq for portability over Bash braces. That way your script works in more shell environments. If in doubt, check the official guide-they reference stuff like this a lot. Agree?
C tbh, but if it specifically said Bash then D could work too.
Be respectful. No spam.