0

I have a directory named bin that has a file called build-code, file type is displayed as "file".

When opened with notepad, the code looks like this:

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

rm -rf build
mkdir build

cp jspm_packages/system.src.js build/system.src.js
cp jspm_packages/system-polyfills.src.js build/system-polyfills.src.js

./bin/build-root
./bin/build-common-deps

./bin/build-home
./bin/build-navbar
./bin/build-angular1
./bin/build-react -p
./bin/build-angular2
./bin/build-vue
./bin/build-svelte
./bin/build-preact
./bin/build-vanillajs

When I try to run this file by navigating to bin and typing in build-code, I get the following error (PowerShell):

'.\bin\build-code' is not recognized as an internal or external command, operable program or batch file.

And bash:

$ build-code
bash: build-code: command not found

I have tried this in both PowerShell and GitBash. I have virtually no experience with writing scrupts for either (this is third-party code). What gives? Is this an invalid script, or am I doing something wrong?

As a side note, what is set -e doing? Seems to be setting some var, but I have no idea why.

P.S. npm tag is on the list, because this was initially being called from npm, but I am trying manually now.

5
  • 1
    If you're in the bin directory all the rest of the paths look rather suspect, unless you have another bin directory under bin. . . Is your script executable? And set -e will cause the script to exit if any command exits with a code other than 0. It's setting a bash option, not a variable Commented Jan 5, 2017 at 15:15
  • I will look into that, thanks. Commented Jan 5, 2017 at 15:18
  • 1
    try ./build-code in bash Commented Jan 5, 2017 at 16:07
  • 1
    That's a bash script, so you probably need to invoke your build from bash (Cygwin?). Otherwise you need to rewrite them as batch scripts (with the extension .bat or .cmd). Commented Jan 5, 2017 at 16:29
  • @H_squared That worked. Also, Angsar - yea, had to run it in GitBash. Commented Jan 5, 2017 at 18:17

2 Answers 2

1

Have you tried changing ./bin/... to the absolute path?

Also, you mentioned navigating into bin before running the script, seems like the script expects to be run from the parent directory instead.

Sign up to request clarification or add additional context in comments.

2 Comments

Would that really cause the error I am getting though? I am checking paths to other scripts as Eric suggested, but it seems like the 'build-code' script shouldn't be failing if it's valid.
even if you're inside the bin directory, you'll need to call it with ./build-code since it's not part of the PATH environment variable
0
  1. Add the sha-bang {#!/bin/bash} line at the very top. (which you've done sort of)

  2. Using chmod u+x scriptname make the script executable. (did you do this?)

  3. Place the script under /usr/local/bin folder.

After that, you should be able to run the script. This is typically what I do in CentOS / RHEL when needing to write and run a small script. What exactly is your script doing? building a folder structure? If so this too can be done pretty easily with PowerShell too.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.