Operating System - HP-UX
1752815 Members
6035 Online
108789 Solutions
New Discussion юеВ

copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

 
dhiraj_deshmukh
Occasional Advisor

copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

Hello,

I am trying to run the file 'copy_files_in_dir.sh' and getting the error that - `(' is not expected. Could somebody help me please. Below is the content at line # 35.

mondate_pd=$echo $var | awk '{ printf "%s\n", substr( $1, 6, 6 ) }'

Please let me know if I need to provide more details.

Thanks & Regards,
Dhiraj
11 REPLIES 11
James R. Ferguson
Acclaimed Contributor

Re: copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

Hi:

You want:

mondate_pd=$(echo $var | awk '{ printf "%s\n", substr( $1, 6, 6 ) }')

...in order to set the 'mondae_pd' variable. Notice the $(...)

Regards!

...JRF...
dhiraj_deshmukh
Occasional Advisor

Re: copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

Thanks for your reply. I replaced that line and tried to run but again the same error. I had read some threads on internet and I have a doubt that it might be an issue with the setting but I am not sure. I am new to shell script. Please kindly let me know.

Thanks & Regards,
Dhiraj
James R. Ferguson
Acclaimed Contributor

Re: copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

Hi (again):

There is nothing wrong with the corrected syntax I offered.

I should point out that the shell's reporting of the line number at which an error occurs is somewhat fuzzy. Generally, the error is reported a few lines after the real problem.

You can better expose things by running your script with tracing:

# sh -x ./myscript 2>&1|more

If you post your whole script it would be easier to resolve, too.

Regards!

...JRF...
dhiraj_deshmukh
Occasional Advisor

Re: copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

script file is attached here.

Thanks again.

Kind Regards,
Dhiraj
James R. Ferguson
Acclaimed Contributor

Re: copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

Hi (again):

Your script appears to have been mangled. The first problem is:

ls -ltr | grep : | grep -v "^d" | awk '{ print $6 "-" $7 " " $8 " " $9 }' | awk '//

...which occurs at line-24. There is no continuation of the last 'awk' script nor is the line itself continued

Regards!

...JRF...
dhiraj_deshmukh
Occasional Advisor

Re: copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

Ohhh Okk.. Thanks for pointing out this error. I will try to fix it and then run the file again. I will update you what I get.

Thanks for your time to help me.

Kind Regards,
Dhiraj
dhiraj_deshmukh
Occasional Advisor

Re: copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

Hi..
I found that in line 24, awk comand is required at the end since its followed by if else clause. There is awk '// at the end of line 24 but I guess only awk ' is required so I removed '//' part and ran the file but again same error. I am learning new things and trying to debug it again :). will let you if I find anything else till tomorrow.

Thanks & Regards,
Dhiraj
dhiraj_deshmukh
Occasional Advisor

Re: copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

Hello Sir,

I tried to get something out of the script but still I am getting the same error. Can you please help me out

Thanks & Regards,
Dhiraj
James R. Ferguson
Acclaimed Contributor

Re: copy_files_in_dir.sh[12]: Syntax error at line 35 : `(' is not expected

Hi (again):

> I tried to get something out of the script but still I am getting the same error. Can you please help me out

OK, disregard what I said originally. This is one seriously convoluted script.

Using the last post of your code. Change these lines as shown:

Change lines 35-36 from:

mondate_pd=$(echo $var | awk '{ printf "%s\n", substr( $1, 6, 6 ) }')
curr_yr=$echo `date -u` | awk '{ print $6}'

...to this:

mondate_pd=echo $var | awk '{printf "%s\n",substr\($1,6,6\)}'
curr_yr=echo `date -u` | awk '{ print $6}'

...and see if this solves your problem.

Regards!

...JRF...