Knife shebang


#1

As I start developing more and more knife exec scripts, it would be nice to make them executable via a shebang, i.e.

#! /usr/bin/env knife

I’ve tried various incantations without success. Has anyone had success?

Thanks.

Joe

#2

Hi Joe,

On Apr 30, 2013, at 1:57 PM, joe.nuspl nuspl@nvwls.com wrote:

As I start developing more and more knife exec scripts, it would be nice to make them executable via a shebang, i.e.

#! /usr/bin/env knife

I’ve tried various incantations without success. Has anyone had success?

Are you writing knife scripts, a la “knife exec”? Or knife plugins?

If the former:

#!/usr/bin/env knife exec

If the latter, you don’t run them directly, instead call as a knife subcommand:

knife mything


Joshua Timberman | Opscode, Inc.
Twitter/GitHub: jtimberman


#3

Maybe it is because I’m on CentOS 5.x but this does not work. It was trying to find an executable in $PATH called “knife exec” (with the embedded space).

So I created a wrapper script called “knife-exec”

#! /bin/bash
exec /usr/bin/env knife exec $*

and then did:

#! /usr/bin/env knife-exec

in the scripts.

Maybe I’ll enhance knife to check if ARGV[0] was of the form /full/path or ./local it would be treated as if “exec” was specified.

Joe