Skip to main content
Evidently a typo in the first improvement you listed so I changed `||` to `&&`.
Source Link
Wildcard
  • 37.5k
  • 30
  • 149
  • 284

An alias is expanded simply by replacing the alias by its definition (as a list of tokens, not a string, which is basically equivalent to taking the string and adding a space at the end). So stopdev; true is expanded to

cd $HOME/website; make website_stop; make backend_stop; ; true
                                                      ^^^

Since you can't have two consecutive semicolons in the shell syntax, that's a syntax error.

You can remove the ;, and that will make stopdev; startev work, but it isn't good, because any argument you pass to stopdev will be passed to make backend_stop, which is probably not desirable.

You should make this a function. Also, don't run the make commands if the cd command fails.

stopdev () {
  cd "$HOME/website" && {
    make website_stop
    make backend_stop
  }
}

An improvement would be to make the function return a failure code even if make website_stop fails but make backend_stop succeeds.

stopdev () {
  cd "$HOME/website" && {
    make website_stop
    ret=$?
    make backend_stop ||&& return $ret
  }
}

Note that this leaves you in the ~/website directory. To avoid changing the directory of the shell process, run the function in a subshell.

stopdev () (
  cd "$HOME/website" && {
    make website_stop
    ret=$?
    make backend_stop && return $ret
  }
)

Alternatively, with GNU make, you can use its -C option.

stopdev () {
  make -C "$HOME/website" website_stop
  ret=$?
  make -C "$HOME/website" backend_stop && return $ret
}

If the targets never fail, just pass them both.

stopdev () (
  cd "$HOME/website" && make website_stop backend_stop
)

or

stopdev () {
  make -C "$HOME/website" website_stop backend_stop
}

An alias is expanded simply by replacing the alias by its definition (as a list of tokens, not a string, which is basically equivalent to taking the string and adding a space at the end). So stopdev; true is expanded to

cd $HOME/website; make website_stop; make backend_stop; ; true
                                                      ^^^

Since you can't have two consecutive semicolons in the shell syntax, that's a syntax error.

You can remove the ;, and that will make stopdev; startev work, but it isn't good, because any argument you pass to stopdev will be passed to make backend_stop, which is probably not desirable.

You should make this a function. Also, don't run the make commands if the cd command fails.

stopdev () {
  cd "$HOME/website" && {
    make website_stop
    make backend_stop
  }
}

An improvement would be to make the function return a failure code even if make website_stop fails but make backend_stop succeeds.

stopdev () {
  cd "$HOME/website" && {
    make website_stop
    ret=$?
    make backend_stop || return $ret
  }
}

Note that this leaves you in the ~/website directory. To avoid changing the directory of the shell process, run the function in a subshell.

stopdev () (
  cd "$HOME/website" && {
    make website_stop
    ret=$?
    make backend_stop && return $ret
  }
)

Alternatively, with GNU make, you can use its -C option.

stopdev () {
  make -C "$HOME/website" website_stop
  ret=$?
  make -C "$HOME/website" backend_stop && return $ret
}

If the targets never fail, just pass them both.

stopdev () (
  cd "$HOME/website" && make website_stop backend_stop
)

or

stopdev () {
  make -C "$HOME/website" website_stop backend_stop
}

An alias is expanded simply by replacing the alias by its definition (as a list of tokens, not a string, which is basically equivalent to taking the string and adding a space at the end). So stopdev; true is expanded to

cd $HOME/website; make website_stop; make backend_stop; ; true
                                                      ^^^

Since you can't have two consecutive semicolons in the shell syntax, that's a syntax error.

You can remove the ;, and that will make stopdev; startev work, but it isn't good, because any argument you pass to stopdev will be passed to make backend_stop, which is probably not desirable.

You should make this a function. Also, don't run the make commands if the cd command fails.

stopdev () {
  cd "$HOME/website" && {
    make website_stop
    make backend_stop
  }
}

An improvement would be to make the function return a failure code even if make website_stop fails but make backend_stop succeeds.

stopdev () {
  cd "$HOME/website" && {
    make website_stop
    ret=$?
    make backend_stop && return $ret
  }
}

Note that this leaves you in the ~/website directory. To avoid changing the directory of the shell process, run the function in a subshell.

stopdev () (
  cd "$HOME/website" && {
    make website_stop
    ret=$?
    make backend_stop && return $ret
  }
)

Alternatively, with GNU make, you can use its -C option.

stopdev () {
  make -C "$HOME/website" website_stop
  ret=$?
  make -C "$HOME/website" backend_stop && return $ret
}

If the targets never fail, just pass them both.

stopdev () (
  cd "$HOME/website" && make website_stop backend_stop
)

or

stopdev () {
  make -C "$HOME/website" website_stop backend_stop
}
Source Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k

An alias is expanded simply by replacing the alias by its definition (as a list of tokens, not a string, which is basically equivalent to taking the string and adding a space at the end). So stopdev; true is expanded to

cd $HOME/website; make website_stop; make backend_stop; ; true
                                                      ^^^

Since you can't have two consecutive semicolons in the shell syntax, that's a syntax error.

You can remove the ;, and that will make stopdev; startev work, but it isn't good, because any argument you pass to stopdev will be passed to make backend_stop, which is probably not desirable.

You should make this a function. Also, don't run the make commands if the cd command fails.

stopdev () {
  cd "$HOME/website" && {
    make website_stop
    make backend_stop
  }
}

An improvement would be to make the function return a failure code even if make website_stop fails but make backend_stop succeeds.

stopdev () {
  cd "$HOME/website" && {
    make website_stop
    ret=$?
    make backend_stop || return $ret
  }
}

Note that this leaves you in the ~/website directory. To avoid changing the directory of the shell process, run the function in a subshell.

stopdev () (
  cd "$HOME/website" && {
    make website_stop
    ret=$?
    make backend_stop && return $ret
  }
)

Alternatively, with GNU make, you can use its -C option.

stopdev () {
  make -C "$HOME/website" website_stop
  ret=$?
  make -C "$HOME/website" backend_stop && return $ret
}

If the targets never fail, just pass them both.

stopdev () (
  cd "$HOME/website" && make website_stop backend_stop
)

or

stopdev () {
  make -C "$HOME/website" website_stop backend_stop
}