LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash Function Problem (https://www.linuxquestions.org/questions/linux-software-2/bash-function-problem-840556/)

Gary Baker 10-26-2010 11:36 AM

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

druuna 10-26-2010 01:03 PM

Hi,

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

Hope this helps.

druuna 10-26-2010 01:18 PM

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.

colucix 10-26-2010 02:02 PM

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 >>> "; }


All times are GMT -5. The time now is 04:05 AM.