0

In some cases I need to pass in an additional prepended parameter to the command line args used when I call exec. How can I accomplish this?

if [ -z "$MILL_HOME" ] ; then
   exec $MILL_EXEC_PATH "$@"
else
   MILL_EXEC_ARGS=("--home" "$MILL_HOME" "$@") 
   exec $MILL_EXEC_PATH "$MILL_EXEC_ARGS"
fi

In the case above I am trying to make --home $MILL_HOME be the first argument passed in when $MILL_HOME is present.

Damian
  • 2,709
  • 2
  • 29
  • 40
  • 1
    Why are you doing `"$@"` in the else part, when you should be doing `"${MILL_EXEC_ARGS[@]}"` – Inian Jul 02 '21 at 15:17
  • Well I typed it wrong, but I think your `${MILL_EXEC_ARGS[@]}` is what I was looking for. – Damian Jul 02 '21 at 15:33
  • @Inian feel free to submit your comment as the answer. – Damian Jul 02 '21 at 15:34
  • unless you plan on using the array later in the script, could you drop the array assignment and go with: `exec $MILL_EXEC_PATH --home "$MILL_HOME" "$@"` ... ?? – markp-fuso Jul 03 '21 at 20:41

0 Answers0