简体   繁体   中英

Bash (or PowerShell script failing) - why?

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.

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

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.

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM