# Can't run bash script in after\_success: "\[\[: not found"

**URL:** <https://travis-ci.community/t/cant-run-bash-script-in-after-success-not-found/8669>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** travis-build\
**Created:** [May 18, 2020, 4:42am UTC](https://travis-ci.community/t/cant-run-bash-script-in-after-success-not-found/8669 "2020-05-18T04:42:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhernando](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/rhernando/32/4488_2.png) [@rhernando](https://travis-ci.community/u/rhernando)\
**Post date:** [May 18, 2020, 4:42am UTC](https://travis-ci.community/t/cant-run-bash-script-in-after-success-not-found/8669/1 "2020-05-18T04:42:02Z")

</div>

I’m trying to run a specific bash script using `after_success`. The reason is that I want to push changes to docker hub but do it only when the master branch is updated, not when the PR passes the tests.

This is a super simplified version in order to keep it as short as possible.

The folder structure is like this

```auto
|-- scripts
    |-- dockerhub.sh
|-- index.js
|-- Dockerfile
|-- package.json
|-- .travis.yml

```

**.travis.yml**

```auto
sudo: required

services:
  - docker

script:
  - npm run test

after_success:
  - ./scripts/dockerhub.sh

```

**dockerhub.sh**

```auto
#!/bin/sh

if [["$TRAVIS_BRANCH" != "master"]]; then
  echo "We're not on the master branch!!."
  # This will analyze the current branch and react accordingly
  exit 0
fi

if [["$TRAVIS_BRANCH" == "master"]]; then
  echo "We ARE on the master branch!!!."
  # This will analyze the current branch and react accordingly
  exit 0
fi

```

In the build process I see this:

```auto
./scripts/dockerhub.sh: 3: ./scripts/dockerhub.sh: [[: not found
./scripts/dockerhub.sh: 9: ./scripts/dockerhub.sh: [[: not found

```

If I change the `dockerhub.sh` to this:

```auto
#!/bin/sh

if [["$TRAVIS_BRANCH" != "master"]]; then
  echo "We're not on the master branch!!."
  # This will analyze the current branch TheDFury and react accordingly
  exit 0
fi

```

I still get the first error `./scripts/dockerhub.sh: 3: ./scripts/dockerhub.sh: [[: not found`

This is the latest build:  
[https://travis-ci.com/github/rhernandog/dockerhub-travis-push/builds/166637696](https://travis-ci.com/github/rhernandog/dockerhub-travis-push/builds/166637696)

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [May 18, 2020, 9:04am UTC](https://travis-ci.community/t/cant-run-bash-script-in-after-success-not-found/8669/2 "2020-05-18T09:04:15Z")

</div>

Hey @rhernando,

It seems like the build is passing now. Can you confirm this? If you’re still having issues please post back and I’ll be glad to help you.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [May 18, 2020, 11:10am UTC](https://travis-ci.community/t/cant-run-bash-script-in-after-success-not-found/8669/3 "2020-05-18T11:10:52Z")

</div>

> [@rhernando](#):
>
> ```auto
> #!/bin/sh
> 
> ```

Change the shebang to `#!/bin/bash`.  
“`[[`” is Bash-specific syntax. Even when `/bin/sh` is Bash, it emulates the traditional `sh` and doesn’t support extended syntax when it’s invoked as “`sh`”.

---

<div class="post-metadata">

**Author:** ![rhernando](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/rhernando/32/4488_2.png) [@rhernando](https://travis-ci.community/u/rhernando)\
**Post date:** [May 19, 2020, 2:56pm UTC](https://travis-ci.community/t/cant-run-bash-script-in-after-success-not-found/8669/4 "2020-05-19T14:56:12Z")

</div>

@native-api

That change plus a few environmental variables made the trick.

Thank you kind sir!!!
