6 Fixes For “syntax error near unexpected token”

6 Fixes For “syntax error near unexpected token”

What is it?

This problem (syntax error near unexpected token) usually occurs in Cygwin, a Unix-type of environment and command-line interface for Microsoft Windows.

 

It will be triggered when you try to run a shell script which has been created or edited in the older Mac systems or Windows/DOS.

In Windows/DOS text files, a new line is usually the combination of two characters including a Carriage Return (r) which is followed by a Line Feed (n) character.

Prior to Mac OS X in Mac systems, a line break used to be the single Carriage Return (r) character. Modern Mac OS & Linux or Unix systems make use of the Unix style Line Feed (n) line breaks.

Also Read:  How to Update the Firmware of Philips Hue Accessories: Bulbs and Bridge

Cygwin might fail to process the available scripts that are formatted in Old Mac OS or Windows/DOS systems because of the presence of the extra Carriage Return (r) character.

How to Fix The “Syntax Error Near Unexpected Token” Error?

First Fix: Use The “dos2unix.exe” Command

To solve the problem of the error “syntax error near unexpected token”, the users are recommended to make use of the “dos2unix.exe” command.

This command will be useful in converting the script to the Unix readable format.

 

Second Fix: Use The “cat” Command

If you are making use of a Linux system, then you can follow the steps:

  1. Make use of the “cat” command for displaying the contents of the script.
  2. Then, you can utilize the commands of copy & paste for copying what was displayed. Paste the copied content on a new file. The new file would visually appear to be similar as the old one. However, it will no longer contain the non-printable characters and will remove the errors.
  3. Set the permissions on the file that has been newly created such that it can be executed.
  4. Run the new script by using the “sh –vx

Correct the error “syntax error near unexpected token” by following these steps!

Unix VS Linux

You’ve probably heard of the word Linux. You probably know it’s an operating system.

In fact, it’s the kernel that’s employed at the core of the Android operating system. It also operates on an array of devices, including desktops and laptops. It really is the hub of Chrome OS. You can get it on servers, it also runs on Raspberry Pi.

Now you might have also heard of Unix and of course, they appear similar. And you might be wondering: are they exactly the same thing? Could they be compatible?

Are they totally different? If you would like to know what is the difference between UNIX and Linux, this coding vlogger explains: to comprehend the difference between these two operating systems, you need to know a bit about the history of how we got to where we are today

UNIX was invented by two men, that is Ken Thompson and Dennis Ritchie. Now you may have heard those two names before. Dennis Ritchie, needless to say, is renowned for creating the C programming language.

Ken Thompson is very renowned for not only inventing lit UNIX, but he also created the utf-8 character encoding that people make use of all the time today and he is the co-inventor of Google’s Go programming language.

So we’re dealing with legends in computing.

In the late 1960s early 1970s, Ritchie and Thompson, along with people like Kernighan, were implementing an operating system called Multics (Multiplexed Information and Computing Service). That was built to run multiple programs. Watch the video for a full history!

Additional Resources

If you have some specific issues with the following- click the link to visit the relevant support forum.

syntax error near unexpected token:

  1. `(‘ python
  2. (‘ bash
  3. (‘ c
  4. fi’
  5. then’

Other Common Issues

  • newline’
  • fi’
  • done’
  • then’
  • else’
  • (‘ python
  • $’ r”
  • $’do r”
  • elif’
  • do
  • echo’
  • (‘ bash
  • newline’ doctype html ‘
  • (‘ c
  • if’
  • mac
  • (‘ shell
  • newline’ mac
  • ‘ in shell script
  • (‘ linux
  • awk
  • am_init_automake
  • a’
  • ‘agg”
  • alsa ‘
  • (‘ array
  • apache ‘
  • ampersand
  • alias’
  • sys.argv’
  • newline’ arch ‘
  • token (‘ awk
  • bash array
  • token ampersand
  • xcb-aux
  • token alias
  • os.path.abspath’
  • oken newline’
  • newline’ line 1 arch ‘
  • bash
  • bash function
  • bash script
  • break’
  • bashrc
  • bracket
  • (‘ bash mysql
  • brew
  • blas
  • ‘then’ bash script
  • newline’ bash
  • else’ bash
  • do’ bash
  • done’ bash
  • fi’ bash
  • dist-bzip2′
  • $’ r” bash
  • elif’ bash
  • (‘ git bash
  • cd’
  • curl’
  • configure
  • case
  • cscope ‘
  • check ‘
  • cygwin
  • cat
  • (‘ c program
  • config.nice’
  • conda.cli.main’
  • centos
  • config.h’
  • (‘ csh
  • crypto ‘
  • case statement
  • cares ‘
  • (‘ cpp
  • cron
  • (‘ comm
  • done’ while
  • done’ in unix
  • do’ while
  • do for loop
  • done bash script
  • disable-static’
  • do’ in linux
  • done’ cygwin
  • deps ‘
  • django_settings_module
  • do bash
  • dbus ‘
  • done’ while loop
  • done’ while read
  • esac’
  • elif’ in unix
  • export’
  • external’
  • ‘ exec
  • enable’
  • e2fs ext2fs’
  • else if’
  • expr
  • ‘ expect
  • (‘ eclipse
  • elif’ cygwin
  • elif in linux
  • token echo’
  • if else
  • from’
  • foreign’
  • fi’ in shell script
  • function
  • for loop
  • fuse ‘
  • find’
  • (‘ foreach
  • (‘ flask
  • file’
  • fft ‘
  • found_pkgconfig ‘
  • freetype ‘
  • token from’
  • 1.14 flavour
  • shell function
  • glib ‘
  • git-directory’
  • grep’
  • gtk ‘
  • (‘ git
  • gpio.board’
  • gnu’
  • gnutls ‘
  • g2 ‘
  • (‘ gcc
  • ggplot2 ‘
  • goto’
  • gdk_pixbuf
  • gst ‘
  • newline’ git
  • newline’ golang
  • token newline’
  • d token (‘
  • nexpected token
  • hello world ‘
  • hello ‘
  • (‘ hive
  • html
  • newline’ html
  • d token hello world ‘
  • token (‘ in hive
  • ted token (‘
  • syslog-ng-config.h ‘
  • token newline’ doctype html ‘
  • ected token
  • ected token newline’
  • in
  • in shell script
  • ifeq
  • in python
  • import
  • in unix
  • (‘ int main(void)’
  • iconv’
  • imagemagick’
  • illegal
  • int’
  • token i’
  • token if’
  • fi shell
  • $’in r”
  • (‘ in c
  • (‘ in mysql
  • java
  • javascript
  • jenkins
  • jack ‘
  • json
  • jquery
  • js
  • (‘ node js
  • os.path.join’
  • token (‘
  • in json at position 0
  • ed token fi’
  • token newline’
  • d token wall
  • unexpected token (‘
  • ksh
  • kali
  • libpng ‘
  • libsn ‘
  • linux
  • libusbmuxd ‘
  • libusb
  • linux shell script
  • line’
  • let’
  • lzma liblzma ‘
  • libcurl ‘
  • lt_decl_varnames ‘
  • libgnutls ‘
  • libxml2 ‘
  • ls’
  • lasso ‘
  • lua
  • makefile
  • mkdir’
  • mac terminal
  • mv’
  • meaning
  • mongodb
  • maximum’
  • mavx
  • (‘ mysql
  • (‘ main
  • m4′
  • matlab
  • ^m’
  • mongo
  • minor-version’
  • token (‘ mysql
  • fi’ mac
  • do mac

CATEGORIES:

Tech

Comments are closed

Latest Comments

No comments to show.