Operating System - HP-UX
1832269 Members
3376 Online
110041 Solutions
New Discussion

Re: 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...
dhiraj_deshmukh
Occasional Advisor

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

Sorry but I get the following error after I replaced those 2 lines-


copy_files_in_dir.sh[12]: .: A test command parameter is not valid.
Usage: scp [options] [[user@]host1:]file1 [...] [[user@]host2:]file2
Options:
-1 Forces scp to use protocol 1.
-2 Forces scp to use protocol 2.
-4 Forces scp to use IPv4 addresses only.
-6 Forces scp to use IPv6 addresses only.
-B Selects batch mode (prevents asking for passwords or passphras-es).
-C Compression enable.
-c cipher Selects the cipher to use for encrypting the data transfer.
-F ssh_config Specifies an alternative per-user configuration file for ssh.
-i identity_file Selects the file from which the identity(private key)for RSA authentication is read.
-l limit Limits the used bandwidth, specified in Kbit/s.
-o ssh_option Used to pass options to ssh in the format used in ssh_config file.
-P port Specifies the port to connect to on the remote host.
-p Preserves modification times, access times, and modes from the original file.
-q Disables the progress meter.
-r Recursively copy entire directories.
-R buf.size Specify receive buffer size.
-S program Name of program to use for the encrypted connection.
-v Verbose mode.




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):

> Sorry but I get the following error after I replaced those 2 lines-
>copy_files_in_dir.sh[12]: .: A test command parameter is not valid.
>Usage: scp [options] [[user@]host1:]file1 [...] [[user@]host2:]file2

Errors such as these arise from poor programming practices. You have statements like:

if [ $2 = "." -o $2 = "s14139/" -o $2 = "s14041/" ]

...which is $2 isn't defined, generate an error. You need to protect against this misbehavior by quoting :

if [ "$2" = "." -o "$2" = "s14139/" -o "$2" = "s14041/" ]

Regards!

...JRF...