Bash Function Syntax Error Near Unexpected Token
Contents |
HCL Search Reviews Search ISOs Go to Page... LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie Bash Error: syntax error near unexpected token `{ User Name Remember Me? Password Linux - Newbie
Bash Call A Function
This Linux forum is for members that are new to Linux. Just starting out bash syntax error near unexpected token done' and have a question? If it is not in the man pages or the how-to's this is the place! Notices Welcome to bash syntax error near unexpected token echo' LinuxQuestions.org, a friendly and active Linux Community. You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe
Bash Syntax Error Near Unexpected Token (' Ubuntu
to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today! Note that registered members see fewer ads, and ContentLink is completely disabled once you log in. Are you new to LinuxQuestions.org? Visit the following links: Site Howto | Site FAQ | Sitemap | Register Now If you have any problems with the registration process or your account login, please contact us. If
Bash Syntax Error Near Unexpected Token Else'
you need to reset your password, click here. Having a problem logging in? Please visit this page to clear all LQ-related cookies. Introduction to Linux - A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. 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. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Click Here to receive this Complete Guide absolutely free. Search this Thread 03-04-2010, 06:07 AM #1 araouf LQ Newbie Registered: Mar 2010 Posts: 1 Rep: Bash Error: syntax error near unexpected token `{ Hi, I am new to shell scripting, bash specifically. I am trying to run the following script: Code: #!/bin/bash #send notification emails sendMails(){ emails=$1 # get all email ids } processLine(){ line="$@" # get all args echo -e "***************
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us bash syntax error near unexpected token fi' Learn more about Stack Overflow the company Business Learn more about hiring developers
Bash Syntax Error Near Unexpected Token Then'
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack bash syntax error near unexpected token do' Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up basic bash syntax issue - syntax error http://www.linuxquestions.org/questions/linux-newbie-8/bash-error-syntax-error-near-unexpected-token-%60%7B-793124/ near unexpected token up vote 0 down vote favorite I think my script does what its meant to do, at first I just had #!/bin/bash for file in /home/parallels/Desktop/trashcan/* do echo "Would you like to delete - " $file done I then wanted to add the obvious missing functionality so I now have #!/bin/bash for file in /home/parallels/Desktop/trashcan/* do echo "Would you like to delete - " http://stackoverflow.com/questions/18001127/basic-bash-syntax-issue-syntax-error-near-unexpected-token $file read line if [$line == y|Y] sudo rm $file fi done Thats where I'm at now, I did at first try to use a case statement instead of the if as I have a working script with the case statement I'd need but simply copying it over gives me the same error - syntax error near unexpeted token, I get this for fi and done linux bash unix syntax share|improve this question edited Aug 1 '13 at 18:54 MPelletier 10.2k106296 asked Aug 1 '13 at 17:50 user1872493 1 I believe you need spaces behind [ and before ]. And I'm not sure if the | or will work. Could you just try [ $line == y ]? –Johannes P Aug 1 '13 at 17:56 With the fix in either of the answers, this will still treat an input of "yes" or "Yes" as "no". –Keith Thompson Aug 1 '13 at 18:11 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote [ is a command, so it must be separated by whitespace from its first argument: if [ "$line" = y ] || [ "$line" = Y ]; then sudo r
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more http://unix.stackexchange.com/questions/192518/grom-keyword-in-bash-throws-unexpected-token about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating http://unix.stackexchange.com/questions/296354/syntax-error-near-unexpected-token-in-a-bash-function-definition/296362 systems. 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 top grom() keyword in bash throws unexpected '(' syntax error token up vote 3 down vote favorite 2 I'm not entirely sure why I'm getting the error in my .bash_profile syntax error near unexpected token `(' when I use the keyword grom() for my function. I wanted to create a bash function that will just automatically rebase my master branch with origin # git status alias gs='git status' # git stash list alias gsl='git stash list' grom() { branch_name="$(git symbolic-ref --short -q HEAD)" git fetch && git rebase origin/master syntax error near && git checkout master && git rebase origin/master && git checkout $branch_name } # git stash apply. must append stash@{num} alias gsa="git stash apply" When I change the name of the function, it compiles fine. I couldn't find grom as a keyword so I'm not sure what the issue is. If I rename the function to anything else like git-rom or even something like groms, it compiles fine. Is there some special keywords that do not work? This is on Mac OS X. bash shell-script alias function profile share|improve this question edited Mar 25 '15 at 23:15 Gilles 369k666681119 asked Mar 25 '15 at 21:26 aug 1416 3 If you're using bash, you may have better luck declaring it as function grom() { … }. Another possibility is that there is an open-parenthesis in the output of your first git command; try git checkout "$branch_name" as your last chained command, which may get you a git error, but at least you'd know what needs fixing. (Sorry, I'm not yet a git guru) –Adam Katz Mar 25 '15 at 21:35 You should probably show people the immediately preceding lines, too. –JdeBP Mar 25 '15 at 21:38 @AdamKatz Adding function in front seemed to fix the issue. I tried the latter option and I still got the error. Very intriguing considering I have other functions in my bash-profile that do not requir