Reputation: 2796
I am wondering why the variables ($HOST
and $i
) are not being passed to the timeout 1 bash -c 'cat < /dev/null > /dev/tcp/$HOST/$i' && echo $?
command.
#!/bin/bash
HOST=$1
for i in {0..8889}
do
OPENPORT=$(timeout 1 bash -c 'cat < /dev/null > /dev/tcp/$HOST/$i' && echo $?)
if [ "$OPENPORT" == 0 ]
then
echo -e "Port $i is open on $HOST.\n"
fi
done
Upvotes: 0
Views: 51
Reputation: 3880
Its because your variables are in single quotes ('
). Use double quotes ("
) instead.
From gnu.org
Enclosing characters in single quotes (
'
) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.
Upvotes: 2