dimanche 4 mars 2018

Shorthand for declaring a boolean value in bash

Say I have this bash function:

foobar_force(){
  foorbar "$@" --force
}

foobar () {
   local is_force=$(test "$2" == "--force");
}

I am looking for two things - I would like to only test if the last argument is "--force" not just the second argument, if possible.

Also I am looking for some shorthand I can use to declare is_force as true or false.

I guess the only way I know how to do that is to use:

if [[ "$2" == "--force" ]]; then
 local is_force="yes" ;
fi

Aucun commentaire:

Enregistrer un commentaire