Jon889
(Jonathan Bailey)
1
The swift command lets you run a Swift file really easily just by doing swift File.swift it also lets you easily evaluate a one liner like swift -e "print(100)"
Is there anyway to combine the two? using definitions in the file in the evaluated line. eg:
File.swift:
let someConfig = "production"
swift File.swift -e "print(someConfig)" would output production
Currently I am doing:
swift -e "$(cat File.swift)"$'\n print(someConfig)'
which is kind of ugly especially with the whole $'\n ...' needed to get an actual newline
jrose
(Jordan Rose)
2
Not perfect, but (cat File.swift && echo 'print(someConfig)') | swift - will work as well as your current solution does. But that's not really an answer.
Jon889
(Jonathan Bailey)
3
Ah thanks, I did have to make it (cat File.swift && echo -e '\n print(someConfig)') | swift - but that's a fair bit better as it removes the need for the lesser known ANSI-C Quoting