This howto shows you how to execute a bash script against the local file system.
The bash script that will be executed is:
We can print the content with the data cat command
tabul data cat command/hello-world@howto
#!/usr/bin/env bash
# First argument is the name and default to "world" if not provided
name=${1:-World}
# Output the greeting
echo "Hello $name"
To make a script executable, we need to:
In our case, to execute
the runtime data uri is:
(command/hello-world@howto)@tmp
A runtime is always executed at access/time, so we will just print it with the tabul data print command to execute it.
tabul data print --strict-selection '(command/hello-world@howto)@tmp'
# The quotes are only mandatory in bash because parenthesis are a bash token (ie subshell)
# We execute it with a strict-selection flag so that we get an error if the executable file is not found.
(command/hello-world@howto)@tmp
lines
-----------
Hello World
To pass an argument, we need to create a command manifest to set one or more command attributes
tabul data cat command/hello-foo--command.yml@howto
kind: command
spec:
# the runtime data uri
data-uri: (command/hello-world@howto)@tmp
# The data definition (attributes)
data-def:
# A list of arguments passed to the command
arguments:
- Foo # The first argument, the name
Note that we could have used the following runtime data uri
data-uri: (hello-world@md)@tmp
Why? because the manifest is located next to the script, so we could use the md connection (manifest directory)
Printing this command manifest will execute the script with the foo argument.
tabul data print command/hello-foo--command.yml@howto
(command/hello-world@howto)@tmp
lines
---------
Hello Foo
In the same way, you can copy the manifest, change the arguments and create any resource dynamically
tabul data print command/hello-bar--command.yml@howto
(command/hello-world@howto)@tmp
lines
---------
Hello Bar