sda100
asked on
Help with script (sh)
I'm trying to write a script (using sh) that will create dhcp.conf from a list of data. The part which I'm getting stuck on is how to specify a subnet range. Using Bash, the (( a=1, a<10, a++)) syntax works, but not in sh. Is there an equivalent way?
I was thinking about working from an IP address range specified like:
10.1.44.0-10.1.45.255
10.1.36.41-10.1.36.45
I can easily split this up using DOS batch language, but I don't know how to using sh. My intention is to (with the exception of 0 and 255), search a file for each IP address, and if found, construct the relevant information for dhcp.conf. I can even accept just writing the variables in the program rather than trying to parse those lines, but I still don't know how to loop through each IP address:
This is how I would do it in bash. BUT can it be done in sh?
for (( a=44; a<46; a++)); do
for ((b=1; b<255; b++)); do
echo 10.1.$a.$b
done
done
The alternative is to not use sh at all. But I wanted to because I thought it was 'standard' as far as shell scripting goes. Am I mistaken here... ie. is 'bash' seen as standard and pretty much guaranteed to be installed on any system?
Many thanks,
Steve :)
I was thinking about working from an IP address range specified like:
10.1.44.0-10.1.45.255
10.1.36.41-10.1.36.45
I can easily split this up using DOS batch language, but I don't know how to using sh. My intention is to (with the exception of 0 and 255), search a file for each IP address, and if found, construct the relevant information for dhcp.conf. I can even accept just writing the variables in the program rather than trying to parse those lines, but I still don't know how to loop through each IP address:
This is how I would do it in bash. BUT can it be done in sh?
for (( a=44; a<46; a++)); do
for ((b=1; b<255; b++)); do
echo 10.1.$a.$b
done
done
The alternative is to not use sh at all. But I wanted to because I thought it was 'standard' as far as shell scripting goes. Am I mistaken here... ie. is 'bash' seen as standard and pretty much guaranteed to be installed on any system?
Many thanks,
Steve :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Steve ;)