{"id":3638,"date":"2017-04-03T12:53:32","date_gmt":"2017-04-03T07:23:32","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=3638"},"modified":"2017-04-03T12:53:32","modified_gmt":"2017-04-03T07:23:32","slug":"linux-please-help-bash-syntax-error","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/linux-please-help-bash-syntax-error\/","title":{"rendered":"[Solved -4 Answers] LINUX &#8211; Bash syntax error: unexpected end of file"},"content":{"rendered":"<p><label class=\"label label-warning\">PROBLEM:<\/label><\/p>\n<p>Bash syntax error: unexpected end of file<\/p>\n<p>Here&#8217;s the code:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">bash code<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">#!\/bin\/bash<br\/># june 2011<br\/><br\/>if [ $# -lt 3 -o $# -gt 3 ]; then<br\/>   echo &quot;Error... Usage: $0 host database username&quot;<br\/>   exit 0<br\/>Fi<\/code><\/pre> <\/div>\n<ul>\n<li>after running sh file.sh:<\/li>\n<li>syntax error: unexpected end of file<\/li>\n<\/ul>\n<p><label class=\"label label-info\">SOLUTION 1:<\/label><\/p>\n<ul>\n<li>file.sh is with CRLF line terminators.<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">bash code<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">dos2unix file.sh<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<p>then the problem will be fixed.<\/p>\n<ul>\n<li>You can install dos2unix in ubuntu with this:<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">bash code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">sudo apt-get install dos2unix<\/code><\/pre> <\/div>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">bash code<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">die () { test -n &quot;$@&quot; &amp;&amp; echo &quot;$@&quot;; exit 1 }<\/code><\/pre> <\/div>\n<p><label class=\"label label-info\">SOLUTION 2:<\/label><\/p>\n<ul>\n<li>Terminate bodies of single-line functions with semicolon<\/li>\n<\/ul>\n<p>I.e. this innocent-looking snippet will cause the same error:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\"> die () { test -n &quot;$@&quot; &amp;&amp; echo &quot;$@&quot;; exit 1 }<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<ul>\n<li>To make the dumb parser:<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">bash code<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">die () { test -n &quot;$@&quot; &amp;&amp; echo &quot;$@&quot;; exit 1; }<\/code><\/pre> <\/div>\n<p><label class=\"label label-info\">SOLUTION 3:<\/label><\/p>\n<ul>\n<li>We needed on cygwin :-<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">bash code<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\"> export SHELLOPTS<br\/> set -o igncr<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<p>in .bash_profile . This way we didn&#8217;t need to run unix2dos<\/p>\n<p><label class=\"label label-info\">SOLUTION 4:<\/label><\/p>\n<ul>\n<li>Make sure the name of the directory in which the .sh file is present does not have a space character.<\/li>\n<li>e.g: Say if it is in a folder called &#8216;New Folder&#8217;, you&#8217;re bound to come across the error that you&#8217;ve cited. Instead just name it as &#8216;New_Folder&#8217;.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Bash syntax error &#8211; Make sure the name of the directory in which the .sh file is present does not have a space character.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1699],"tags":[6821,6827,6810,6825,6792,6811,6803,6807,6806,6805,6814,6818,6813,6804,6829,6808,6819,6817,6823,6822,6830,6826,6794,6796,6820,6801,6799,6824,6809,6831,6791,6800,6795,6793,6797,6815,6798,6812,6790,6828,6816,6802],"class_list":["post-3638","post","type-post","status-publish","format-standard","hentry","category-linux","tag-abs-function-in-c","tag-bash-directory-of-script","tag-bash-function","tag-bash-shell-variables","tag-bash-syntax-error-unexpected-token","tag-bash-variable","tag-bashas","tag-debug-shell-script","tag-define-call","tag-define-echo","tag-define-empty","tag-define-function-in-c","tag-define-precede","tag-double-marker-test-wiki","tag-echo-function","tag-environment-variables-in-linux","tag-exit-function-in-c","tag-function-declaration","tag-function-in-html","tag-functions-in-bash","tag-functions-in-linux-shell-script","tag-gnu-bash-cve-2014-6271","tag-ksh-syntax-error-unexpected","tag-line-1-syntax-error-unexpected-word-expecting","tag-line-function","tag-sh-create-array","tag-sh-1-syntax-error-unexpected-python","tag-shell-script-function","tag-shellshock","tag-shellshock-test","tag-syntax-error-unexpected-bash-array","tag-syntax-error-unexpected-bash-function","tag-syntax-error-unexpected-ubuntu","tag-syntax-error-at-line-unexpected","tag-syntax-error-done-unexpected","tag-syntax-error-near-unexpected-token","tag-syntax-error-unexpected-c","tag-syntax-error-unexpected-end-of-file","tag-syntax-error-unexpected-bash","tag-useful-bash-scripts","tag-what-is-bash-in-linux","tag-what-is-bash-scripting"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/3638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=3638"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/3638\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=3638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=3638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=3638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}