bash script use cut command at variable and store result at another variable
The awk solution is what I would use, but if you want to understand your problems with bash, here is a revised version of your script.
#!/bin/bash -vx##config file with ip addresses like 10.10.10.1:80file=config.txtwhile read line ; do ##this line is not correct, should strip :port and store to ip var ip=$( echo "$line" |cut -d\: -f1 ) ping $ipdone < ${file}
You could write your top line as
for line in $(cat $file) ; do ...
(but not recommended).
You needed command substitution $( ... )
to get the value assigned to $ip
reading lines from a file is usually considered more efficient with the while read line ... done < ${file}
pattern.
I hope this helps.