iex can be used for interactively experimenting with elixir. If this experimentation becomes elaborate, it can be useful to store the commands in a file. This post covers working with files that store elixir code snippets. Attention is paid to code that depends on mix project modules.
A single line can be run from the command line.
Something more elaborate probably wants to live in a file.
The above file be run from the command line as is, but it will not have acces to modules in the mix project.
Run the file with mix run if any mix project modules are referenced.
Note that c or Code.load_file can be used to load the file in iex.
Code.load_file can be used to load one file from another file. This is fragile if using relative paths.
To run mix code snippets directly from the command line,
add the following file to some place on your path.
Make mix-snippet executable.
The mix-snippet shebang can now be used.
Code snippets that depend on the mix project can now be executed from the command line.