Skip to content
Home » Oracle » How to Resolve bash: syntax error near unexpected token `('

How to Resolve bash: syntax error near unexpected token `('

bash: syntax error near unexpected token (

Tried to export some data by data pump, but it failed with bash: syntax error near unexpected token (.

[oracle@test ~]$ expdp system/password@orclpdb dumpfile=test.dmp logfile=test.log schemas=hr exclude=table:\"in ('EMPLOYEES', 'DEPARTMENTS')\"
-bash: syntax error near unexpected token `('

It seems a shell command error about left round brackets.

Solution

I know you have escaped the double quotes just like we introduced in how to expdp as sysdba, but that's not enough to pass the value into data pump.

In this case, we used EXCLUDE parameter to specify some tables that need to be excluded. Actually, some special characters as below all need to be escaped in the parameter.

  • Double quotes
  • Single quotes
  • Round brackets

In Linux and Unix-based OS, we usually use backslash (\) to escape special characters.

Let's see the executable command line we composed.

[oracle@test ~]$ expdp system/password@orclpdb dumpfile=test.dmp logfile=test.log schemas=hr exclude=table:\"in \(\'EMPLOYEES\', \'DEPARTMENTS\'\)\"             
...
Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01":  system/********@orclpdb dumpfile=test.dmp logfile=test.log schemas=hr exclude=table:"in ('EMPLOYEES', 'DEPARTMENTS')"
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
...

As we can see, we escaped every special characters and passed it into EXCLUDE parameter successfully. Not only EXCLUDE, but also INCLUDE parameter has the same problem.

To mitigate character escaping problems, Oracle recommends that we use PARFILE to hide parameters from the command line.

Leave a Reply

Your email address will not be published. Required fields are marked *