LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-21-2011, 02:35 PM   #1
akshaykb1
LQ Newbie
 
Registered: Nov 2011
Location: Chicago Land
Posts: 2

Rep: Reputation: Disabled
-bash: syntax error near unexpected token `('


Hello,

I am trying to create an alias that I can use in .bash_profile. Before creating an alias, I tested the following positively.

tail -f $ORACLE_BASE/diag/rdbms/`echo $ORACLE_SID |awk '{print tolower\($1\)}'`/$ORACLE_SID/trace/alert_$ORACLE_SID.log

But when I try to create an alias called alertt using below:

alias alertt='tail -f /u01/app/oracle/diag/rdbms/`echo $ORACLE_SID |awk '{print tolower($1)}'`/$ORACLE_SID/trace/alert_$ORACLE_SID.log'

it throws the following error:
-bash: syntax error near unexpected token `('

Any help is appreciated.

--AK
 
Old 11-21-2011, 02:46 PM   #2
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
The problem is that the quotes around the awk code actually close the starting quote and open a new pair of quotes respectively. See the parts highlighted in blue:
Code:
alias alertt='tail -f /u01/app/oracle/diag/rdbms/`echo $ORACLE_SID |awk '{print tolower($1)}'`/$ORACLE_SID/trace/alert_$ORACLE_SID.log'
To solve this you could embed the whole alias definition in double quotes instead of single ones. Even better you could define a function instead and use export -f to make it available to any other (sub)shell.
 
1 members found this post helpful.
Old 11-21-2011, 02:59 PM   #3
akshaykb1
LQ Newbie
 
Registered: Nov 2011
Location: Chicago Land
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you, double quotes did the trick.

Quote:
Originally Posted by colucix View Post
The problem is that the quotes around the awk code actually close the starting quote and open a new pair of quotes respectively. See the parts highlighted in blue:
Code:
alias alertt='tail -f /u01/app/oracle/diag/rdbms/`echo $ORACLE_SID |awk '{print tolower($1)}'`/$ORACLE_SID/trace/alert_$ORACLE_SID.log'
To solve this you could embed the whole alias definition in double quotes instead of single ones. Even better you could define a function instead and use export -f to make it available to any other (sub)shell.
Thank you!!! it worked. I am new to UNIX world. Can you elaborate more on "define a function instead". An example would be good.

--AK
 
Old 11-21-2011, 06:45 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
As you are in bash, you could try:
Code:
alias alertt='tail -f /u01/app/oracle/diag/rdbms/${ORACLE_SID,,}/$ORACLE_SID/trace/alert_$ORACLE_SID.log'
 
  


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] bash: syntax error near unexpected token `(' rc5gd Programming 6 07-13-2010 08:54 PM
[SOLVED] bash: syntax error near unexpected token `else' lucmove Programming 9 05-10-2010 09:03 PM
bash: syntax error near unexpected token `(' Folklore Linux - Newbie 1 05-02-2010 03:35 AM
-bash: syntax error near unexpected token ty1on Linux - Newbie 3 08-26-2009 02:19 PM
Trouble with Bash -- syntax error near unexpected token `fi' anamericanjoe Programming 5 05-19-2006 02:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:42 AM.

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