In our previous article, we have seen how to setup Swift programming language in Ubuntu Linux and how to invoke Swift’s interactive shell to play with Swift language.
In this article, we will see how to run a Swift program saved in a file from Ubuntu Linux terminal as a script.
1. Open a text editor and type the given below Swift code and save to a file called
2. Open a terminal and type the given below command
Now we can see an output as given below
4. Add the shebang line
#!/usr/bin/env swift to the file
#!/usr/bin/env swift print("HelloWorld")
5. Make the file
$chmod ugo+x hello.swift
6. Run the file
Now we will get same output as in Step 3, but with out using