Table of Contents

About

This howto shows you how to execute a bash script against the local file system.

Steps

The bash script

The bash script that will be executed is:

  • a simple hello world sample application
  • that accepts optionally 1 argument to set the name of the greeted person.
  • located in the command directory of the howto connection

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"

Creating the command data uri

To make a script executable, we need to:

In our case, to execute

the runtime data uri is:

(command/hello-world@howto)@tmp

Executing the command

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

Passing an argument

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

Same script, different argument, different resource

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