Running/Interpreting a swift file and evaluating a line of code (-e)

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:


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

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.

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