I set the value of $port outside of a while loop
read in a file and pull two variable out of it, sometimes the second variable(port) is set, sometimes not.. but if not, then i want it to have a default value
seems to be the only way i can solve this is by explicitly checking for $port on each line and if its empty, set it inside the while loop.. any way to preserve the global value of $port in the loop?
contents of test1:
read in a file and pull two variable out of it, sometimes the second variable(port) is set, sometimes not.. but if not, then i want it to have a default value
seems to be the only way i can solve this is by explicitly checking for $port on each line and if its empty, set it inside the while loop.. any way to preserve the global value of $port in the loop?
Code:
#!/bin/bash
export port=161
export file=~/test1
while read server port; do
echo "devcreate ${server%%.*} $server $port"
done < $file
contents of test1:
Code:
fqdn1.hostname.com
fqdn2.hostname.com
fqdn3.hostname.com 4161
fqdn4.hostname.com 161
fqdn5.hostname.com 4161