{"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\u2019s the code:<\/p>\n[pastacode lang=\u201dbash\u201d manual=\u201d%23!%2Fbin%2Fbash%0A%23%20june%202011%0A%0Aif%20%5B%20%24%23%20-lt%203%20-o%20%24%23%20-gt%203%20%5D%3B%20then%0A%20%20%20echo%20%22Error\u2026%20Usage%3A%20%240%20host%20database%20username%22%0A%20%20%20exit%200%0AFi%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\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[pastacode lang=\u201dbash\u201d manual=\u201ddos2unix%20file.sh%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\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[pastacode lang=\u201dmarkup\u201d manual=\u201dsudo%20apt-get%20install%20dos2unix\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[pastacode lang=\u201dbash\u201d manual=\u201ddie%20()%20%7B%20test%20-n%20%22%24%40%22%20%26%26%20echo%20%22%24%40%22%3B%20exit%201%20%7D%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\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[pastacode lang=\u201dbash\u201d manual=\u201d%20die%20()%20%7B%20test%20-n%20%22%24%40%22%20%26%26%20echo%20%22%24%40%22%3B%20exit%201%20%7D%0A\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<ul>\n<li>To make the dumb parser:<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201ddie%20()%20%7B%20test%20-n%20%22%24%40%22%20%26%26%20echo%20%22%24%40%22%3B%20exit%201%3B%20%7D%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><label class=\"label label-info\">SOLUTION 3:<\/label><\/p>\n<ul>\n<li>We needed on cygwin :-<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201d%20export%20SHELLOPTS%0A%20set%20-o%20igncr%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<p>in .bash_profile . This way we didn\u2019t 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 \u2018New Folder\u2019, you\u2019re bound to come across the error that you\u2019ve cited. Instead just name it as \u2018New_Folder\u2019.<\/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}]}}