Skip to main content
added information from comment
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

When I try to combine two normal commands using the ; character (eg. ls; cd) it works fine. However, I have two aliases that I've created (stopdev and startdev), and if I try to combine them:

stopdev; startdev 

or even if I just try and add a semi-colon after one:

stopdev; 

I get a syntax error:

bash: syntax error near unexpected token `;'

I also have the same problem if I use &&:

stopdev && startdev 

bash: syntax error near unexpected token `&&'

I'm confused by this because I had thought that aliases were just like any other commands ... but clearly they aren't.

So, two questions:

  1. Why is using ; or && with an alias call invalid?
  2. Is there any way (other than creating a stopstartdev alias) to easily run these two commands together?

Here's the definition of stopdev:

alias stopdev="cd $HOME/website; make website_stop; make backend_stop;" 

When I try to combine two normal commands using the ; character (eg. ls; cd) it works fine. However, I have two aliases that I've created (stopdev and startdev), and if I try to combine them:

stopdev; startdev 

or even if I just try and add a semi-colon after one:

stopdev; 

I get a syntax error:

bash: syntax error near unexpected token `;'

I also have the same problem if I use &&:

stopdev && startdev 

bash: syntax error near unexpected token `&&'

I'm confused by this because I had thought that aliases were just like any other commands ... but clearly they aren't.

So, two questions:

  1. Why is using ; or && with an alias call invalid?
  2. Is there any way (other than creating a stopstartdev alias) to easily run these two commands together?

When I try to combine two normal commands using the ; character (eg. ls; cd) it works fine. However, I have two aliases that I've created (stopdev and startdev), and if I try to combine them:

stopdev; startdev 

or even if I just try and add a semi-colon after one:

stopdev; 

I get a syntax error:

bash: syntax error near unexpected token `;'

I also have the same problem if I use &&:

stopdev && startdev 

bash: syntax error near unexpected token `&&'

I'm confused by this because I had thought that aliases were just like any other commands ... but clearly they aren't.

So, two questions:

  1. Why is using ; or && with an alias call invalid?
  2. Is there any way (other than creating a stopstartdev alias) to easily run these two commands together?

Here's the definition of stopdev:

alias stopdev="cd $HOME/website; make website_stop; make backend_stop;" 
Source Link

Why Can't I Call Two Aliases With ";"?

When I try to combine two normal commands using the ; character (eg. ls; cd) it works fine. However, I have two aliases that I've created (stopdev and startdev), and if I try to combine them:

stopdev; startdev 

or even if I just try and add a semi-colon after one:

stopdev; 

I get a syntax error:

bash: syntax error near unexpected token `;'

I also have the same problem if I use &&:

stopdev && startdev 

bash: syntax error near unexpected token `&&'

I'm confused by this because I had thought that aliases were just like any other commands ... but clearly they aren't.

So, two questions:

  1. Why is using ; or && with an alias call invalid?
  2. Is there any way (other than creating a stopstartdev alias) to easily run these two commands together?