Results 1 to 10 of 12
I have about 2 or 3 questions.
Using a for loop (for i in $(command);do echo $i;done) how can I get it to accept a full line as a var?
...
- 09-12-2007 #1
Newbie looking for bash scripting help
I have about 2 or 3 questions.
Using a for loop (for i in $(command);do echo $i;done) how can I get it to accept a full line as a var?
ie
param1 param2 param3
comes out as
param1
param2
param3
How can I get it to take the whole line as a var? (I will have multiple lines)
Part 2: How can I take that same line, and left align the line and the right align personal output?
ie
p1 p2 p3<---- left align, right align ----------------->FAIL
p1 p2 p3<---- left align, right align ----------------->PASS
?
Thanks in advance
- 09-13-2007 #2
put param1 2 and 3 in quotes, and it will get passed as a whole line. You can demonstrate this with a simple script:
Run the program like ./program one two three four five and see what happens.Code:#!/bin/bash for i in $@; do echo $i done echo "NOW WITH QUOTES" for i in "$@"; do echo $i done
- 09-13-2007 #3
As far as part two goes, if you're only doing PASS or FAIL, echo COLS - 6 spaces, then echo pass or fail. I don't know of an easier way really.
So something like
Code:#!/bin/bash for i in "$LINE"; do echo -n $LINE while (COUNT < COLS - 6); do echo -n ' ' let COUNT+=1 done echo $STATUS done
- 09-13-2007 #4
- 09-13-2007 #5
I keep trying the above, but get failures. I have also tried replacing COLS with COLUMNS without success.
#!/bin/bash
STATUS="FAIL"
TEST="1 2 3 4 5"
for i in "$TEST"; do
echo -n $TEST
while (COUNT < COLS - 6); do
echo -n ' '
let COUNT+=1
done
echo $STATUS
done
--------------------------------- RESULTS ------------------------
# ./test.sh
1 2 3 4 5./test.sh: line 9: COLUMNS: No such file or directory
FAIL
- 09-13-2007 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
Just one qns for you, you want to parse netstat's output right? Show what you want to see from netstat's output.
- 09-13-2007 #7
xxx.xxx.xxx.132:22 0.0.0.0:* LISTEN
xxx.xxx.xxx.132:143 xxx.xxx.xxx.xxx:1407 ESTABLISHED
xxx.xxx.xxx.133:22 xxx.xxx.xxx.xxx:1408 ESTABLISHED
xxx.xxx.xxx.133:143 xxx.xxx.xxx.xxx:1407 ESTABLISHED
I want most left aligned and LISTEN, ESTABLISHED, ETC right aligned. I want to color them based on the local IP (multiple IPs bound). The color code I can do, just the other stuff I am having issues with
- 09-13-2007 #8Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 09-13-2007 #9
- 09-13-2007 #10
Yea sorry about that syntactical error up there (i've been doing a lot of c lately) it should be
It was saying that because > isn't used for comparison in Bash, it's used for file redirection.Code:while [ $COUNT -lt $(($COLS - 6)) ]; do echo whatyouwanthere let COUNT+=1 done


Reply With Quote
