/usr/bin/env: ‘bash -xe’: No such file or directory

Hi, I’m running build on the stack “Android & Docker, on Ubuntu 16.04 (pre-installed tools)” and I have bash script that starts with #!/usr/bin/env: bash -xe.
And I’m getting the following error when it is being executed:

/usr/bin/env: ‘bash -xe’: No such file or directory

It is working fine on my local machine

This script is being executed from npm as part of package.json scripts.

Thank you.

Hi @max,

Can you please add the whole script to check it in context?

1 Like

Did you manage to solve the issue @max?

Hello,

Can you please add the whole script to check it in context?

actual script

// hello.sh

#!/usr/bin/env bash -xe

echo "Hello world"

// “scripts” section in package.json

"hello": "./hello.sh"

invokation of the script as part of “Script” step

npm run hello

Did you manage to solve the issue @max?

I didn’t resolve this issue but I found a workaround of hardcoding path to bash as #!/bin/bash

@max strange… I’d say it’s an npm issue most likely, running the script directly (e.g. as a Script step or from a Script step) works as expected:

+------------------------------------------------------------------------------+
| (0) script@1.1.4                                                             |
+------------------------------------------------------------------------------+
| id: script                                                                   |
| version: 1.1.4                                                               |
| collection: https://github.com/bitrise-io/bitrise-steplib.git                |
| toolkit: bash                                                                |
| time: 2017-09-22T12:13:16Z                                                   |
+------------------------------------------------------------------------------+
|                                                                              |
Hello world
|                                                                              |
+---+---------------------------------------------------------------+----------+
| ✓ | script@1.1.4                                                  | 2.71 sec |
+---+---------------------------------------------------------------+----------+

config:

  primary:
    steps:
    - script@1.1.4:
        inputs:
        - content: |-
            #!/usr/bin/env bash -xe

            echo "Hello world"

OK, I think I found the issue.

How the script step runs the given script, and how I tested to run the script: bash /path/to/script

So the script is ran / invoked through bash directly.

If you simply just chmod +x the script and try to run you indeed get the error you mentioned:

$ chmod +x test.sh 
$ ./test.sh 

/usr/bin/env: ‘bash -xe’: No such file or directory

I ran this on a local Ubuntu 17.04

The shebang #!/usr/bin/env bash -xe works on macOS but not on any Linux I tried.

A bit more debugging: the issue seems to be the -xe postfix. This works on Linux too:

#!/usr/bin/env bash
set -ex

echo "Hello world"

so #!/usr/bin/env bash is actually :+1:, but on Linux you can’t pass additional params to it, you have to do that in a separate set command/line.

I hope this helps :slight_smile:

1 Like

Yeah… this approach works, thanks a lot!

1 Like

Any time :wink: