Merge pull request #12205 from soapy1/shell-agnostic-for-loop

Make shell script for loop shell agnostic
This commit is contained in:
Sophia Castellarin 2021-02-22 17:07:41 -06:00 committed by GitHub
commit d52e0e1b09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -17,7 +17,7 @@ module Vagrant
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
grep -w '#{name}' /etc/hosts || {
for i in {1..#{loop_bound}}; do
for i in #{[*1..loop_bound].join(' ')}; do
grep -w "127.0.${i}.1" /etc/hosts || {
echo "127.0.${i}.1 #{name} #{basename}" >> /etc/hosts
break

View File

@ -20,8 +20,8 @@ describe "Vagrant::Util::GuestHosts" do
end
it "can add hostname to loopback interface" do
subject.add_hostname_to_loopback_interface(comm, "test.end", 40)
expect(comm.received_commands[0]).to match(/for i in {1..40}; do/)
subject.add_hostname_to_loopback_interface(comm, "test.end", 4)
expect(comm.received_commands[0]).to match(/for i in 1 2 3 4; do/)
expect(comm.received_commands[0]).to match(/echo \"127.0.\${i}.1 test.end test\" >> \/etc\/hosts/)
end
end
@ -35,8 +35,8 @@ describe "Vagrant::Util::GuestHosts" do
end
it "can add hostname to loopback interface" do
subject.add_hostname_to_loopback_interface(comm, "test.end", 40)
expect(comm.received_commands[0]).to match(/for i in {1..40}; do/)
subject.add_hostname_to_loopback_interface(comm, "test.end", 4)
expect(comm.received_commands[0]).to match(/for i in 1 2 3 4; do/)
expect(comm.received_commands[0]).to match(/echo \"127.0.\${i}.1 test.end test\" >> \/etc\/hosts/)
end
end