Bash Syntax Error Missing expecting “thenâ€
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
For the following lines in my Makefile I get the error
Syntax error: end of file unexpected (expecting "then")
Code:
if [ ! -d upload-api/app-router/ ] then
git clone someRepo upload-api/app-router/
fi
I've tried with a semicolon after the brackets but I get still the same error
bash make makefile
add a comment |Â
up vote
3
down vote
favorite
For the following lines in my Makefile I get the error
Syntax error: end of file unexpected (expecting "then")
Code:
if [ ! -d upload-api/app-router/ ] then
git clone someRepo upload-api/app-router/
fi
I've tried with a semicolon after the brackets but I get still the same error
bash make makefile
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
For the following lines in my Makefile I get the error
Syntax error: end of file unexpected (expecting "then")
Code:
if [ ! -d upload-api/app-router/ ] then
git clone someRepo upload-api/app-router/
fi
I've tried with a semicolon after the brackets but I get still the same error
bash make makefile
For the following lines in my Makefile I get the error
Syntax error: end of file unexpected (expecting "then")
Code:
if [ ! -d upload-api/app-router/ ] then
git clone someRepo upload-api/app-router/
fi
I've tried with a semicolon after the brackets but I get still the same error
bash make makefile
asked Aug 21 at 8:40
Barsch
192
192
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
14
down vote
You need to put then in next line or use semicolon
if [ ! -d upload-api/app-router/ ]
then
or
if [ ! -d upload-api/app-router/ ];then
1
Note that the spaces before and after;
are optional,if [ ! -d upload-api/app-router/ ];then
(or any combination) is equally valid.
– dessert
Aug 21 at 8:50
1
Totally agree ...
– papampi
Aug 21 at 8:56
add a comment |Â
up vote
3
down vote
In the context of a makefile, I see two things.
First, you need a semicolon or newline before the then
. Shell syntax for if
looks like: if commands... ; then commands... ; fi
(where any semicolon here can be replaced with a newline).
Second, when make
executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:
sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
sh -c 'git clone someRepo upload-api/app-router/' &&
sh -c 'fi'
...which is a syntax error on the first line, with or without the semicolon, because the if
is never finished.
So for a makefile recipe, you would need to let make
know that it should treat the entire if ... fi
block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.
my-target:
↦ if [ ! -d upload-api/app-router/ ] ; then
↦ git clone someRepo upload-api/app-router/ ;
↦ fi
This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
14
down vote
You need to put then in next line or use semicolon
if [ ! -d upload-api/app-router/ ]
then
or
if [ ! -d upload-api/app-router/ ];then
1
Note that the spaces before and after;
are optional,if [ ! -d upload-api/app-router/ ];then
(or any combination) is equally valid.
– dessert
Aug 21 at 8:50
1
Totally agree ...
– papampi
Aug 21 at 8:56
add a comment |Â
up vote
14
down vote
You need to put then in next line or use semicolon
if [ ! -d upload-api/app-router/ ]
then
or
if [ ! -d upload-api/app-router/ ];then
1
Note that the spaces before and after;
are optional,if [ ! -d upload-api/app-router/ ];then
(or any combination) is equally valid.
– dessert
Aug 21 at 8:50
1
Totally agree ...
– papampi
Aug 21 at 8:56
add a comment |Â
up vote
14
down vote
up vote
14
down vote
You need to put then in next line or use semicolon
if [ ! -d upload-api/app-router/ ]
then
or
if [ ! -d upload-api/app-router/ ];then
You need to put then in next line or use semicolon
if [ ! -d upload-api/app-router/ ]
then
or
if [ ! -d upload-api/app-router/ ];then
edited Aug 21 at 8:56
answered Aug 21 at 8:46
papampi
318210
318210
1
Note that the spaces before and after;
are optional,if [ ! -d upload-api/app-router/ ];then
(or any combination) is equally valid.
– dessert
Aug 21 at 8:50
1
Totally agree ...
– papampi
Aug 21 at 8:56
add a comment |Â
1
Note that the spaces before and after;
are optional,if [ ! -d upload-api/app-router/ ];then
(or any combination) is equally valid.
– dessert
Aug 21 at 8:50
1
Totally agree ...
– papampi
Aug 21 at 8:56
1
1
Note that the spaces before and after
;
are optional, if [ ! -d upload-api/app-router/ ];then
(or any combination) is equally valid.– dessert
Aug 21 at 8:50
Note that the spaces before and after
;
are optional, if [ ! -d upload-api/app-router/ ];then
(or any combination) is equally valid.– dessert
Aug 21 at 8:50
1
1
Totally agree ...
– papampi
Aug 21 at 8:56
Totally agree ...
– papampi
Aug 21 at 8:56
add a comment |Â
up vote
3
down vote
In the context of a makefile, I see two things.
First, you need a semicolon or newline before the then
. Shell syntax for if
looks like: if commands... ; then commands... ; fi
(where any semicolon here can be replaced with a newline).
Second, when make
executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:
sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
sh -c 'git clone someRepo upload-api/app-router/' &&
sh -c 'fi'
...which is a syntax error on the first line, with or without the semicolon, because the if
is never finished.
So for a makefile recipe, you would need to let make
know that it should treat the entire if ... fi
block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.
my-target:
↦ if [ ! -d upload-api/app-router/ ] ; then
↦ git clone someRepo upload-api/app-router/ ;
↦ fi
This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.
add a comment |Â
up vote
3
down vote
In the context of a makefile, I see two things.
First, you need a semicolon or newline before the then
. Shell syntax for if
looks like: if commands... ; then commands... ; fi
(where any semicolon here can be replaced with a newline).
Second, when make
executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:
sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
sh -c 'git clone someRepo upload-api/app-router/' &&
sh -c 'fi'
...which is a syntax error on the first line, with or without the semicolon, because the if
is never finished.
So for a makefile recipe, you would need to let make
know that it should treat the entire if ... fi
block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.
my-target:
↦ if [ ! -d upload-api/app-router/ ] ; then
↦ git clone someRepo upload-api/app-router/ ;
↦ fi
This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
In the context of a makefile, I see two things.
First, you need a semicolon or newline before the then
. Shell syntax for if
looks like: if commands... ; then commands... ; fi
(where any semicolon here can be replaced with a newline).
Second, when make
executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:
sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
sh -c 'git clone someRepo upload-api/app-router/' &&
sh -c 'fi'
...which is a syntax error on the first line, with or without the semicolon, because the if
is never finished.
So for a makefile recipe, you would need to let make
know that it should treat the entire if ... fi
block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.
my-target:
↦ if [ ! -d upload-api/app-router/ ] ; then
↦ git clone someRepo upload-api/app-router/ ;
↦ fi
This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.
In the context of a makefile, I see two things.
First, you need a semicolon or newline before the then
. Shell syntax for if
looks like: if commands... ; then commands... ; fi
(where any semicolon here can be replaced with a newline).
Second, when make
executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:
sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
sh -c 'git clone someRepo upload-api/app-router/' &&
sh -c 'fi'
...which is a syntax error on the first line, with or without the semicolon, because the if
is never finished.
So for a makefile recipe, you would need to let make
know that it should treat the entire if ... fi
block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.
my-target:
↦ if [ ! -d upload-api/app-router/ ] ; then
↦ git clone someRepo upload-api/app-router/ ;
↦ fi
This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.
edited Aug 21 at 18:34
answered Aug 21 at 18:25
Jander
1512
1512
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1067414%2fbash-syntax-error-missing-expecting-then%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password