Buck: sh_binary()


This is liable to change in the future.

A sh_binary() is used to execute a shell script.


  • name (required) #

    The name of the sh_binary.

  • main (required) #

    Either the path to the script (relative to the build file), or a build target. This file must be executable in order to be run.

  • resources (defaults to []) #

    A list of files or build rules that this rule requires in order to run. These could be things such as random data files. These files are made available in a directory at run time and are placed relative to their original location in the project repository. This directory's location is determined entirely by Buck; the script should not assume the directory's location. The location is provided to the script in the $BUCK_PROJECT_ROOT environment variable.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their deps or exported_deps attributes. For more information, see visibility.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • labels (defaults to []) #

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query attrfilter().


This sh_binary() just cats a sample data file back at the user.

    name = "script",
    main = "script.sh",
    resources = [
# Sample data file with data we need at runtime
$ echo "I'm a datafile" > data.dat

# Create a simple script that prints out the resource
$ cat > script.sh
cat $BUCK_PROJECT_ROOT/data.dat

# Make sure the script is executable
$ chmod u+x script.sh

# Run the script, and see that it prints out the resource we provided
$ buck run //:script
Building: finished in 1.9 sec (100%) 1/1 jobs, 1 updated
  Total time: 2.1 sec
I'm a datafile