Sathish Sathish - 1 year ago 93
Node.js Question

How to do `cd` and invoke some npm scripts inside csh/sh script?

I am a complete newbie to linux and CSH Scripts, I am currently working on a UI Project with reactjs + node + npm + webpack.

As you may now, i need to run webpack bundling to get complied files.

My project is being deployed on a linux machine.

This is my project structure as shown below,


I need to write a csh script in uibuild.csh file as show above,

So this is what i think pseudocode would be,

The script will be executed from


  1. Need to check Node.js and Npm installed or Not,
    if installed contine
    else exit and throw error

  2. Next, i need to change directory to project/uisrc/

  3. Next, i need to execute the below commands serially

'npm install'
'npm run build'

  1. Next, when the npm run build is successful, build files will located inside project/uisrc/dist/ folder. (i need to check files are there or not here).

  2. After that, i need to move the files from project/uisrc/dist to project/ folder.

  3. then i need to remove the node_modules folder generated inside the path project/uisrc/node_modules

  4. Exit script with no-error

As of now, i have tried checking node installed or not by using this script.

if(`where node` == "") then
printf "\nNode.js and Npm not installed. Please install and continue\n";

But i dunno how to change directory and run scripts ??

Can you someone solve this ?

If you need more details, i happy to provide.

Answer Source
if which node > /dev/null ; then
  printf 'Node.js & NPM installed, continue start builing.. \n'
  printf '\x1B[31m Node.js & NPM is not installed, exiting now.. \x1B[0m \n'
  exit 0;

printf 'Current working Directory :: '
cd ../../uisrc/
printf 'Current working Directory :: '
cd dist/
rm -rf index.html assets fixtures
cd ..
npm install --verbose
npm run build
cd ..
rm -rf index.html assets fixtures
cd uisrc/
mv dist/* ../
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download