shell script giving error

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a small shell script which is throwing error:




unexpected end of file




The script follows:



#!
if [ t -eq 1 ]
then
echo " TEST1 "
else
echo " TEST LAST LOOP "
fi






share|improve this question






















  • What's the output of sed -n l < your-script?
    – Stéphane Chazelas
    Mar 23 at 17:11














up vote
0
down vote

favorite












I have a small shell script which is throwing error:




unexpected end of file




The script follows:



#!
if [ t -eq 1 ]
then
echo " TEST1 "
else
echo " TEST LAST LOOP "
fi






share|improve this question






















  • What's the output of sed -n l < your-script?
    – Stéphane Chazelas
    Mar 23 at 17:11












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a small shell script which is throwing error:




unexpected end of file




The script follows:



#!
if [ t -eq 1 ]
then
echo " TEST1 "
else
echo " TEST LAST LOOP "
fi






share|improve this question














I have a small shell script which is throwing error:




unexpected end of file




The script follows:



#!
if [ t -eq 1 ]
then
echo " TEST1 "
else
echo " TEST LAST LOOP "
fi








share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 16:40









Vlastimil

6,3661146117




6,3661146117










asked Mar 23 at 7:26









Priya

6




6











  • What's the output of sed -n l < your-script?
    – Stéphane Chazelas
    Mar 23 at 17:11
















  • What's the output of sed -n l < your-script?
    – Stéphane Chazelas
    Mar 23 at 17:11















What's the output of sed -n l < your-script?
– Stéphane Chazelas
Mar 23 at 17:11




What's the output of sed -n l < your-script?
– Stéphane Chazelas
Mar 23 at 17:11










3 Answers
3






active

oldest

votes

















up vote
5
down vote













There is nothing in the script that should give that error. If you run the script with sh ./script.sh, it will produce



 TEST LAST LOOP 


as output. If running it with bash ./script.sh you will get the same output, but with an additional "integer expression expected" error since t is not an integer (this may also happen if you run with sh if your sh is implemented by bash). If you run it with ./script.sh, the shell will most likely complain with "No such file or directory" since you have not added a proper #!-line.



In this script, you may use #!/bin/sh as the #!-line as you only use standard POSIX features.



The test [ t -eq 1 ] will never be true as t (the character) is not an integer. If you're setting the variable t to an integer somewhere, use [ "$t" -eq 1 ] in the test.




The only way I can get a shell to say "unexpected end of file" is by converting the script to a DOS text file and running it with bash.



If you get this error, then the script file is probably a DOS text file (possibly due to being created on a Windows machine). You should run dos2unix on the script.



See questions related to dos2unix.






share|improve this answer


















  • 3




    [ t -eq 1] may be true with some sh implementations if a t environment variable has been defined with a value that is an arithmetic expression that resolves to 1. For instance, t=20/20 ksh93 -c '[ t -eq 1 ]' is true. t='a[$(")]' ksh93 -c '[ t -eq 1 ]' would give you a 'end of file' unexpected error.
    – Stéphane Chazelas
    Mar 23 at 17:06







  • 1




    Having said that, I agree the DOS text file format is a much more likely explanation
    – Stéphane Chazelas
    Mar 23 at 17:11










  • @StéphaneChazelas Nicely done with that ksh93 thing, but the wording of the error message won't be exactly the same though.
    – Kusalananda
    Mar 23 at 17:15

















up vote
0
down vote













Missing the shebang line #!/bin/sh and t isn't defined






share|improve this answer
















  • 1




    None of those things would provoke an "unexpected end of file" error.
    – Kusalananda
    Mar 23 at 7:52

















up vote
0
down vote













  • replace #! by #!/bin/sh or run sh ./script.sh, and you must set t as integer $t not t.





share|improve this answer






















  • The answer is spot on, but it could use with a bit of expansion on the reasons for it
    – Bruno9779
    Mar 23 at 16:46










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433004%2fshell-script-giving-error%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote













There is nothing in the script that should give that error. If you run the script with sh ./script.sh, it will produce



 TEST LAST LOOP 


as output. If running it with bash ./script.sh you will get the same output, but with an additional "integer expression expected" error since t is not an integer (this may also happen if you run with sh if your sh is implemented by bash). If you run it with ./script.sh, the shell will most likely complain with "No such file or directory" since you have not added a proper #!-line.



In this script, you may use #!/bin/sh as the #!-line as you only use standard POSIX features.



The test [ t -eq 1 ] will never be true as t (the character) is not an integer. If you're setting the variable t to an integer somewhere, use [ "$t" -eq 1 ] in the test.




The only way I can get a shell to say "unexpected end of file" is by converting the script to a DOS text file and running it with bash.



If you get this error, then the script file is probably a DOS text file (possibly due to being created on a Windows machine). You should run dos2unix on the script.



See questions related to dos2unix.






share|improve this answer


















  • 3




    [ t -eq 1] may be true with some sh implementations if a t environment variable has been defined with a value that is an arithmetic expression that resolves to 1. For instance, t=20/20 ksh93 -c '[ t -eq 1 ]' is true. t='a[$(")]' ksh93 -c '[ t -eq 1 ]' would give you a 'end of file' unexpected error.
    – Stéphane Chazelas
    Mar 23 at 17:06







  • 1




    Having said that, I agree the DOS text file format is a much more likely explanation
    – Stéphane Chazelas
    Mar 23 at 17:11










  • @StéphaneChazelas Nicely done with that ksh93 thing, but the wording of the error message won't be exactly the same though.
    – Kusalananda
    Mar 23 at 17:15














up vote
5
down vote













There is nothing in the script that should give that error. If you run the script with sh ./script.sh, it will produce



 TEST LAST LOOP 


as output. If running it with bash ./script.sh you will get the same output, but with an additional "integer expression expected" error since t is not an integer (this may also happen if you run with sh if your sh is implemented by bash). If you run it with ./script.sh, the shell will most likely complain with "No such file or directory" since you have not added a proper #!-line.



In this script, you may use #!/bin/sh as the #!-line as you only use standard POSIX features.



The test [ t -eq 1 ] will never be true as t (the character) is not an integer. If you're setting the variable t to an integer somewhere, use [ "$t" -eq 1 ] in the test.




The only way I can get a shell to say "unexpected end of file" is by converting the script to a DOS text file and running it with bash.



If you get this error, then the script file is probably a DOS text file (possibly due to being created on a Windows machine). You should run dos2unix on the script.



See questions related to dos2unix.






share|improve this answer


















  • 3




    [ t -eq 1] may be true with some sh implementations if a t environment variable has been defined with a value that is an arithmetic expression that resolves to 1. For instance, t=20/20 ksh93 -c '[ t -eq 1 ]' is true. t='a[$(")]' ksh93 -c '[ t -eq 1 ]' would give you a 'end of file' unexpected error.
    – Stéphane Chazelas
    Mar 23 at 17:06







  • 1




    Having said that, I agree the DOS text file format is a much more likely explanation
    – Stéphane Chazelas
    Mar 23 at 17:11










  • @StéphaneChazelas Nicely done with that ksh93 thing, but the wording of the error message won't be exactly the same though.
    – Kusalananda
    Mar 23 at 17:15












up vote
5
down vote










up vote
5
down vote









There is nothing in the script that should give that error. If you run the script with sh ./script.sh, it will produce



 TEST LAST LOOP 


as output. If running it with bash ./script.sh you will get the same output, but with an additional "integer expression expected" error since t is not an integer (this may also happen if you run with sh if your sh is implemented by bash). If you run it with ./script.sh, the shell will most likely complain with "No such file or directory" since you have not added a proper #!-line.



In this script, you may use #!/bin/sh as the #!-line as you only use standard POSIX features.



The test [ t -eq 1 ] will never be true as t (the character) is not an integer. If you're setting the variable t to an integer somewhere, use [ "$t" -eq 1 ] in the test.




The only way I can get a shell to say "unexpected end of file" is by converting the script to a DOS text file and running it with bash.



If you get this error, then the script file is probably a DOS text file (possibly due to being created on a Windows machine). You should run dos2unix on the script.



See questions related to dos2unix.






share|improve this answer














There is nothing in the script that should give that error. If you run the script with sh ./script.sh, it will produce



 TEST LAST LOOP 


as output. If running it with bash ./script.sh you will get the same output, but with an additional "integer expression expected" error since t is not an integer (this may also happen if you run with sh if your sh is implemented by bash). If you run it with ./script.sh, the shell will most likely complain with "No such file or directory" since you have not added a proper #!-line.



In this script, you may use #!/bin/sh as the #!-line as you only use standard POSIX features.



The test [ t -eq 1 ] will never be true as t (the character) is not an integer. If you're setting the variable t to an integer somewhere, use [ "$t" -eq 1 ] in the test.




The only way I can get a shell to say "unexpected end of file" is by converting the script to a DOS text file and running it with bash.



If you get this error, then the script file is probably a DOS text file (possibly due to being created on a Windows machine). You should run dos2unix on the script.



See questions related to dos2unix.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 23 at 7:47

























answered Mar 23 at 7:41









Kusalananda

102k13201317




102k13201317







  • 3




    [ t -eq 1] may be true with some sh implementations if a t environment variable has been defined with a value that is an arithmetic expression that resolves to 1. For instance, t=20/20 ksh93 -c '[ t -eq 1 ]' is true. t='a[$(")]' ksh93 -c '[ t -eq 1 ]' would give you a 'end of file' unexpected error.
    – Stéphane Chazelas
    Mar 23 at 17:06







  • 1




    Having said that, I agree the DOS text file format is a much more likely explanation
    – Stéphane Chazelas
    Mar 23 at 17:11










  • @StéphaneChazelas Nicely done with that ksh93 thing, but the wording of the error message won't be exactly the same though.
    – Kusalananda
    Mar 23 at 17:15












  • 3




    [ t -eq 1] may be true with some sh implementations if a t environment variable has been defined with a value that is an arithmetic expression that resolves to 1. For instance, t=20/20 ksh93 -c '[ t -eq 1 ]' is true. t='a[$(")]' ksh93 -c '[ t -eq 1 ]' would give you a 'end of file' unexpected error.
    – Stéphane Chazelas
    Mar 23 at 17:06







  • 1




    Having said that, I agree the DOS text file format is a much more likely explanation
    – Stéphane Chazelas
    Mar 23 at 17:11










  • @StéphaneChazelas Nicely done with that ksh93 thing, but the wording of the error message won't be exactly the same though.
    – Kusalananda
    Mar 23 at 17:15







3




3




[ t -eq 1] may be true with some sh implementations if a t environment variable has been defined with a value that is an arithmetic expression that resolves to 1. For instance, t=20/20 ksh93 -c '[ t -eq 1 ]' is true. t='a[$(")]' ksh93 -c '[ t -eq 1 ]' would give you a 'end of file' unexpected error.
– Stéphane Chazelas
Mar 23 at 17:06





[ t -eq 1] may be true with some sh implementations if a t environment variable has been defined with a value that is an arithmetic expression that resolves to 1. For instance, t=20/20 ksh93 -c '[ t -eq 1 ]' is true. t='a[$(")]' ksh93 -c '[ t -eq 1 ]' would give you a 'end of file' unexpected error.
– Stéphane Chazelas
Mar 23 at 17:06





1




1




Having said that, I agree the DOS text file format is a much more likely explanation
– Stéphane Chazelas
Mar 23 at 17:11




Having said that, I agree the DOS text file format is a much more likely explanation
– Stéphane Chazelas
Mar 23 at 17:11












@StéphaneChazelas Nicely done with that ksh93 thing, but the wording of the error message won't be exactly the same though.
– Kusalananda
Mar 23 at 17:15




@StéphaneChazelas Nicely done with that ksh93 thing, but the wording of the error message won't be exactly the same though.
– Kusalananda
Mar 23 at 17:15












up vote
0
down vote













Missing the shebang line #!/bin/sh and t isn't defined






share|improve this answer
















  • 1




    None of those things would provoke an "unexpected end of file" error.
    – Kusalananda
    Mar 23 at 7:52














up vote
0
down vote













Missing the shebang line #!/bin/sh and t isn't defined






share|improve this answer
















  • 1




    None of those things would provoke an "unexpected end of file" error.
    – Kusalananda
    Mar 23 at 7:52












up vote
0
down vote










up vote
0
down vote









Missing the shebang line #!/bin/sh and t isn't defined






share|improve this answer












Missing the shebang line #!/bin/sh and t isn't defined







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 23 at 7:37









jas-

71038




71038







  • 1




    None of those things would provoke an "unexpected end of file" error.
    – Kusalananda
    Mar 23 at 7:52












  • 1




    None of those things would provoke an "unexpected end of file" error.
    – Kusalananda
    Mar 23 at 7:52







1




1




None of those things would provoke an "unexpected end of file" error.
– Kusalananda
Mar 23 at 7:52




None of those things would provoke an "unexpected end of file" error.
– Kusalananda
Mar 23 at 7:52










up vote
0
down vote













  • replace #! by #!/bin/sh or run sh ./script.sh, and you must set t as integer $t not t.





share|improve this answer






















  • The answer is spot on, but it could use with a bit of expansion on the reasons for it
    – Bruno9779
    Mar 23 at 16:46














up vote
0
down vote













  • replace #! by #!/bin/sh or run sh ./script.sh, and you must set t as integer $t not t.





share|improve this answer






















  • The answer is spot on, but it could use with a bit of expansion on the reasons for it
    – Bruno9779
    Mar 23 at 16:46












up vote
0
down vote










up vote
0
down vote









  • replace #! by #!/bin/sh or run sh ./script.sh, and you must set t as integer $t not t.





share|improve this answer














  • replace #! by #!/bin/sh or run sh ./script.sh, and you must set t as integer $t not t.






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 23 at 17:09









Jeff Schaller

31.2k846105




31.2k846105










answered Mar 23 at 16:36









Linux-Programmer

71




71











  • The answer is spot on, but it could use with a bit of expansion on the reasons for it
    – Bruno9779
    Mar 23 at 16:46
















  • The answer is spot on, but it could use with a bit of expansion on the reasons for it
    – Bruno9779
    Mar 23 at 16:46















The answer is spot on, but it could use with a bit of expansion on the reasons for it
– Bruno9779
Mar 23 at 16:46




The answer is spot on, but it could use with a bit of expansion on the reasons for it
– Bruno9779
Mar 23 at 16:46












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433004%2fshell-script-giving-error%23new-answer', 'question_page');

);

Post as a guest













































































3,xIy25nJ76Nl,hQSxXFps diC,NS9c 3d6BCabhys8zPjL5 iPY4HzBA V3or3QN,dOP 10ubQ
PLZ fYuHqr2lWsC,nBVmYgL4ql587VEB5k817R w4,um 4euyj jZ6fvlF

Popular posts from this blog

How to check contact read email or not when send email to Individual?

How many registers does an x86_64 CPU actually have?

Displaying single band from multi-band raster using QGIS