Efficient Command Chaining in Bash: Using Semicolons vs. `&&`
In Bash, when you chain commands using semicolons (;), each command is executed sequentially. This means that Bash will wait for each command to complete before starting the next one. So in your example:
npm install; npm run build; npm run start
npm install will run first. After it completes successfully (whether it succeeds or fails), npm run build will start. Once npm run build has finished, npm run start will execute.
If you want the next command to only run if the previous command was successful (i.e., it exited with a status code of 0 indicating success), you can chain them with && instead:
npm install && npm run build && npm run start
In this case, npm run build will only execute if npm install completes successfully, and npm run start will only execute if both the npm install and npm run build commands are successful.
Using && is often preferred in build scripts and deployment workflows to ensure that each step only proceeds if the previous steps were successful.