LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-26-2010, 11:36 AM   #1
Gary Baker
Member
 
Registered: Mar 2007
Location: Whitsett,NC
Distribution: Slackware 14.1 and MINT 17.1
Posts: 105

Rep: Reputation: 3
Bash Function Problem


Hello:

I am getting the same error for both functions but I can't figure out why? They both should work!

The error is:

bash: syntax error near unexpected token `{place=`echo $@`'

bash: syntax error near unexpected token `{tree'


findlocation() {place=`echo $@`; lynx -dump "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | egrep "address|coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';}

tt(){tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> "}


Thanks to all

Last edited by Gary Baker; 10-27-2010 at 12:57 PM. Reason: I tried the posts by colucix but could not get them to work. Colucix could you get them to work on your machine?
 
Old 10-26-2010, 01:03 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Why the explicit place=`echo $@`, why not: place="$@"

Hope this helps.
 
Old 10-26-2010, 01:18 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi again,

About the tee error: Not sure what it is you are trying to accomplish with that function, but the tee command listens to standard in and I don't see anything 'feeding' it, and which file is it writing to?

input -> tee -> output goes to file _and_ standard out (screen in most cases)


I need new glasses! Read tee instead of tree.......

Hope this helps.

Last edited by druuna; 10-26-2010 at 01:20 PM.
 
Old 10-26-2010, 02:02 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Functions have their own syntax about placing the brackets: the opening bracket must be followed by a newline or a blank space; the closing bracket must be on its own line or eventually on the same line of the preceding commands if and only if the last command is followed by semi-colon. The following alternatives should work:
Code:
tt(){
  tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> "
}
Code:
tt()
{
  tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> "
}
Code:
tt(){ tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> "
}
Code:
tt(){ tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> "; }

Last edited by colucix; 10-26-2010 at 02:03 PM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem with getting array from function (bash) DrLove73 Programming 19 09-25-2009 07:07 AM
BASH - problem with subsequent calls to function with getopts dkrysak Programming 3 03-25-2009 03:28 PM
bash function calling problem arashdx Linux - Newbie 1 03-10-2009 03:42 PM
Bash: Problem to run a function in Case mitramcc Linux - Newbie 1 02-12-2009 02:07 PM
Bash looping or function within a function FirmbIT Programming 2 04-24-2006 01:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration