Use case statement in shell script

This article is an example of how to use case statement in a shell script file.

#!/bin/bash

ARTIFACT=lv-foundation
echo "Choose module you want to build, default to foundation."
echo "1 - common"
echo "2 - model"
echo "3 - foundation"
read module;
case $module in
  1) ARTIFACT=lv-common;;
  2) ARTIFACT=lv-model;;
  3) ARTIFACT=lv-foundation;;
  *) ARTIFACT=lv-foundation;; 
esac

BUILD_TARGET_FOLDER=dist/$ARTIFACT
echo "========================Building " $ARTIFACT " Component Start========================";
ng build $ARTIFACT --configuration production
echo "========================Building " $ARTIFACT " Component End========================";

Above example to trigger production build for a selected angular library.
The artifact default to “lv-foundation”, which is the library name.

# Example output.
Choose module you want to build, default to foundation.
1 - common
2 - model
3 - foundation
1
========================Building  lv-common  Component Start========================
Building Angular Package

------------------------------------------------------------------------------
Building entry point '@leveraon/common'
------------------------------------------------------------------------------
✔ Compiling with Angular sources in Ivy full compilation mode.
✔ Generating FESM bundles
✔ Copying assets
✔ Writing package manifest
✔ Built @leveraon/common

------------------------------------------------------------------------------
Built Angular Package
 - from: /Users/me/git/leveraon-ui-foundation/projects/lv-common
 - to:   /Users/me/git/leveraon-ui-foundation/dist/lv-common
------------------------------------------------------------------------------

Build at: 2023-05-13T13:09:33.916Z - Time: 1957ms

========================Building  lv-common  Component End========================

Scroll to Top