-1

This is the first time i am trying to edit a .sh file on ubuntu

ng build @xyz--abc/my-${library}

I am trying to pass a flag --build-optimizer=false but if i add it to end it is giving error Unknown option: '--build-optimizer'

Need some help on how can I add this flag.

Thanks

raju
  • 6,448
  • 24
  • 80
  • 163
  • Where is `--build-optimizer` coming from? Please show the relevant code and state the exact problem or error. Also see [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – jww Sep 19 '19 at 06:12

2 Answers2

1

Usually commandline argument option parsing is implemented with either the bash builtin getopts or one of the platform specific getopt implementations. While getopts does not support parsing long commandline options the GNU getopt implementation does. This answer points out in detail the differences between the corresponding implementations. For an example on how to use the bash builtin getopts I'll refer to the Advanced Bash Scripting Guide.

In order to give you a correct answer it therefore depends on how the script you're trying to modify implements commandline option parsing.

damb
  • 151
  • 1
  • 5
0
LS_OPTIONS=''

while [ $# -gt 0 ]; do
  case "$1" in
    --color=*)
      colorarg="${1#*=}"
      LS_OPTIONS="${LS_OPTIONS} ${1}"
      ;;
    -a|--all)
      allarg="${1}"
      LS_OPTIONS="${LS_OPTIONS} ${1}"
      ;;
    *)
      printf "* Error: Invalid argument.*\n"
      exit 1
  esac
  shift
done


printf "all   val: %s\n\n" "$allarg"
printf "color val: %s\n\n" "$colorarg"

ls ${LS_OPTIONS}

Parses the arguments and passes them to the underlying ls. Is that what you are trying to achieve?

demo

Mikhail Antonov
  • 1,297
  • 3
  • 21
  • 29
  • actually I have a .sh file in which there are many a things, one line is ng build @xyz--abc/my-${library} and I need to pass an argument --flag = true in it. I dont know how to do that. I really appreciate your efforts – raju Sep 19 '19 at 05:27
  • Just like I passed `--color=yes` argument in the `.sh` file above. Won't it work for you? – Mikhail Antonov Sep 19 '19 at 05:45