Home > Syntax Error > Bash Shell Script Syntax Error Near Unexpected Token

Bash Shell Script Syntax Error Near Unexpected Token

Contents

Wherever there is repetitive code, when a task repeats with only slight variations in procedure, then consider using a function.

function function_name { command... }

navigate here

Unexpected parent process id in output no outgoing connection via ipv4 Is 8:00 AM an unreasonable time to meet with my graduate students and post-doc? Why? In your case, the best way is to double-quote the whole second parameter. more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed

Linux Syntax Error Near Unexpected Token Then'

exit # Invokes "exit ()" function, not "exit" builtin. # Or, similarly: filename=file1 [ -f "$filename" ] && foo () { rm -f "$filename"; echo "File "$filename" deleted."; } || foo I use the pr command in the terminal. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the Can a creature benefit from differently typed speed bonuses all named fast movement?

UNIX is a registered trademark of The Open Group. Will the medium be able to last 100 years? Add this assignment PS4 at the beginning of your script to enable the inclusion of that information: export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' Be sure to use single quotes here! Syntax Error Near Unexpected Token Bash Function Is there a way to make a metal sword resistant to lava?

test is the name of a UNIX®-command, and most likely built into your shell (it's a built-in in Bash) - so you won't be able to run a script with the Linux Syntax Error Near Unexpected Token Newline' Note: This is not an exact replication of your environment (I don't have access to a Mac), however it seems likely to me that the issue is that an editor, somewhere, did you close your if with a fi? This can cause much confusion and many headaches, since lines containing CRs are not what they appear to be when printed.

EOF cat <

Function declarations Why not? # Now, let's invoke the function. _ # __________ # ^^^^^^^^^^ 10 underscores (10 x function name)! # A "naked" underscore is an acceptable function name. # In fact, Syntax highlighting helps you see (you guessed it) syntax errors, such as unclosed quotes and braces, typos, etc.

Linux Syntax Error Near Unexpected Token Newline'

I can execute this correctly on a Fedora machine. –Michael Berkowski Jan 3 '14 at 3:25 1 Can you recreate the entire file? If it's printed to your terminal, a carriage return will effectively place the cursor at the beginning of the current line. Linux Syntax Error Near Unexpected Token Then' If not, why? Syntax Error Near Unexpected Token (' In Linux asked 9 months ago viewed 689 times active 9 months ago Related 14Why did ; after & return an unexpected token error in bash?1“Syntax error near unexpected token '$'\r''” in shell

Why? check over here Remove advertisements Sponsored Links raghunsi View Public Profile Find all posts by raghunsi

Page 1 of 2 1 2 > « Previous Thread | Next Thread » Thread Tools Show Click Here to receive this Complete Guide absolutely free. If not, why? Bash Syntax Error Near Unexpected Token R

more hot questions question feed default about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation Why? It's easy to imagine the ^M is bad in other places too. http://onlinetvsoftware.net/syntax-error/bash-script-syntax-error-near-unexpected-token.php When taking passengers, what should I do to prepare them?

Finding a file starting with '-' dash Why did companions have such high social standing? Bash Syntax Error Near Unexpected Token (' Ubuntu I will get back to you soon. chmod: WARNING: can't access /home/MyHome/out/outFile100203-023547.tmox6324-ra.enable [/output] Created Output Files -rw-r--r-- 1 1957 Feb 3 02:29 outFile100203-022952.tmox6324-ra.enable -rw-r--r-- 1 1958 Feb 3 02:31 outFile100203-023128.tmox6324-ra.disable -rw-r--r-- 1 1957 Feb 3 02:31 outFile100203-023155.tmox6324-ra.enable

However for some reason program cannot open the output file. –YKY Dec 11 '15 at 14:48 Error: Could not open VCF Output file: ./by_chrs_komi/22.recode.vcf –YKY Dec 11 '15 at

Is it possible to check for existence of member template just by identifier? func () { echo "First version of func ()." } func () { echo "Second version of func ()." } func # Second version of func (). If you'd like to contribute content, let us know. Syntax Error Near Unexpected Token In Case Statement zirias View Public Profile View LQ Blog View Review Entries View HCL Entries Find More Posts by zirias 07-10-2010, 01:37 AM #5 grail LQ Guru Registered: Sep 2009 Location:

Why? share|improve this answer answered Nov 8 '13 at 10:29 chaos 13.3k74158 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. weblink You may ask yourself why is this mentioned as debugging tip?

This site is not affiliated with Linus Torvalds or The Open Group in any way. Not the answer you're looking for? It's unexpected because Bash waits for the closing of a compound command: did you close your do with a done? I wrote a script for it.

Should indoor ripened tomatoes be used for sauce? if [ "$USER" = bozo ] then bozo_greet () # Function definition embedded in an if/then construct. { echo "Hello, Bozo." } fi bozo_greet # Works only for Bozo, and other How could banks with multiple branches work in a world without quick communication? more hot questions question feed lang-sh about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation

It looks like you are invoking a shell interpreter that doesn't support that syntax (e.g. Unix & Linux Stack Exchange works best with JavaScript enabled current community chat Unix & Linux Unix & Linux Meta your communities Sign up or log in to customize your list. Here, you don't need process substitution, you can use standard shell pipes: printf "%s\n" "TOP" | paste - - is the standard way to tell paste to read the data from Write logfiles For more complex scripts, it's useful to write to a log file, or to the system log.

How to indicate you are going straight? In your script you're using /bin/sh. /bin/sh apparently is not bash on your system, and the <() syntax is apparently not present in whatever shell /bin/sh is. FunctionsTable of Contents24.1. A similar question and answer that references file encoding is here: bad character showing up in bash script execution share|improve this answer edited Jan 5 '14 at 6:25 answered Jan 5

If you need to reset your password, click here. i.e. $ cat originalfile | tr -d "\r" > newfile then it would execute. The point of my answer is that filetype encoding is often a consideration between operating systems and applications. How does the pilot control the Dassault Rafale?

This site is not affiliated with Linus Torvalds or The Open Group in any way. Blogs Recent Entries Best Entries Best Blogs Blog List Search Blogs Home Forums HCL Reviews Tutorials Articles Register Search Search Forums Advanced Search Search Tags Search LQ Wiki Search Tutorials/Articles Search The time now is 07:43 PM.