Execute from script
Executing a recipe from a script.
A recipe can also be executed from a script. For example, to execute the eli5
recipe for an elephant from a script, create the script sample.sh
on Linux or macOS:
#!/bin/bash
npx ai-writer eli5 --topic elephant --output eli5/elephant
And execute this script with the following command:
sh ./sample.sh
Or sample.bat
on Windows, with the following content:
npx ai-writer eli5 --topic elephant --output eli5/elephant
And execute this script with the following command:
sample.bat
Also PowerShell is a powerful scripting language for the execution of recipes, especially because PowerShell scripts can run on Windows, Linux, and macOS. For example, to execute the eli5
recipe for a collection of topics, create the script eli5-multiple.ps1
:
#!/usr/bin/env pwsh
$topics = "elephant", "giraffe", "lion", "tiger", "zebra"
for ($i=0; $i -lt $topics.length; $i++) {
$topic = $topics[$i]
npx ai-writer eli5 --topic $topic --output "eli5/$topic" --dry-run
}
To execute on Linux or macOS, either execute the following command:
pwsh ./eli5-multiple.ps1
Or make the script executable with the following command:
chmod +x ./eli5-multiple.ps1
And execute the script with the following command:
./eli5-multiple.ps1
See PowerShell) for more information on PowerShell.
See PowerShell Installation for more information on how to install PowerShell on Windows, Linux, and macOS.