Bash Script Problem
Hello Everybody,
Below is the bash script I'm working on. Code:
#!/bin/bash My problem is in the formatted output. The first port scanned prints in this format: |-- Port in green. But the 2nd port prints in green but not indented and without the preceeding |-- Like so..... OUTPUT Code:
root@localhost:~/RECON-master$ ./host-list.sh all.txt PREFERRED OUTPUT: Code:
root@localhost:~/RECON-master$ ./host-list.sh all.txt |
Your problem is the following loop.
Code:
for x in "$OpenPort"; do EDIT: It doesn't look like you're using x, which is also why you're seeing the ports printed as one string. You need to use $x to print each port. |
Got it.
Thanks again, Scrag |
you might want to use shellcheck to check your script. That will give you some hints
|
You seem to have your solution, so I thought I would give you some feedback on the script:
1. Right now the script is fresh in your mind, but several months away it may not be, so I would suggest adding in something to advise what the script requires on the command line to be passed in so $1 and $2 make some sense 2. Further to the above, if you assign those values to variables with meaningful names, it will also help in knowing what is required 3. If this script is to be used by others (or again you later on), do not use a for loop or unnecessary 'cat' to read files. A while loop is better suited in case the data in the files might change format 4. Quote all variables until you find a reason not to, as per solution provided by individual 5. Back ticks are old and not as versatile as $() which can be easily nested as required 6. Another easy solution to your problem would have been to make OpenPort an array like you did 'info' (this helps with the for loop and not the fact that you did not use the correct variable inside the loop) 7. You could look into reducing your grep/cut to use maybe sed or awk Hope some of that helps :) Of course you are free to ignore it all ;) |
Quote:
Scrag |
Deleted.
|
One comment:
the quotes in Code:
for i in "${info[@]}"; do But if you have a simple variable and you want to split on the whitespace in the $variable then you cannot use the protecting quotes. Code:
for x in $OpenPort; do Code:
set -f |
Quote:
Code:
|
All times are GMT -5. The time now is 06:40 AM. |