Search code examples
bashterminalbrowserify

How to set flag in bash function for setting aliases?


This is the command i want to execute

watchify files/[filename].js -t hbsfy -o out/[filename].js

i tried this

javascriptCompile() {
  foo="src/js/files/$1.js -t hbsfy -o src/js/out/$1.js"
    watchify "$foo"
}

alias jc=javascriptCompile
jc main

I get this error

You MUST specify an outfile with -o.


Solution

  • It needs to be an array:

    javascriptCompile () {
      foo=(src/js/files/"$1".js -t hbsfy -o src/js/out/"$1".js)
      watchify "${foo[@]}"
    }
    alias jc=javascriptCompile
    jc main