sh:function 

function definition 

Usage 

l(){  if [ "$TERM" = 'xterm' ]; then echo aaa; fi; }

Trying History, definition 

$ if [ "$TERM" = 'xterm' ]; then echo aaa; fi
aaa

— ok

l(){  if [ "$TERM" = 'xterm' ]; then echo aaa; fi }

— syntax error near unexpected token `}'

 l(){
  if [ "$TERM" = 'xterm' ]; then echo aaa; fi
}

— ok

l(){
 if [ "$TERM" = 'xterm' ]; then echo aaa; fi }

— syntax error near unexpected token `}'

 l(){  if [ "$TERM" = 'xterm' ]; then echo aaa; fi
}

— ok

l(){  if [ "$TERM" = 'xterm' ]; then echo aaa; fi; }

— ok

sh script function return value 

To return success or failure 

return 
# return the status of last executed command
return $?                     # 0: success, others: failure

e.g.:

grep ...
return $?                     # 0: found, 1:no found
test 

To test the return value, use -eq / -ne instead of = / !=, for algebraical equality.

[ $? -ne 0 ] && failure_handling

To return a string 

funcdemo(){
  # Demostrate how a function returns string instead of
  # returning value
  echo "somthing about $1 and $2"
}
result=`funcdemo aaa bbb`