why is this code generating syntax error?pls help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting why is this code generating syntax error?pls help
# 1  
Old 05-21-2008
why is this code generating syntax error?pls help

Code:
#!/bin/sh

copy()
{
source=`stat -c %s $1`
dest=0
cd $2
while [ $source -ge $dest ];do
cp $1 $2 &
pct=`((100 * $dest) / $source )`
dest=`dest+1`
echo -en ".$pct%\b\b\b"
sleep 1
done
}

echo "starting now"
copy /file1 /tmp

This is the code i wrote to make cp address a progress bar...
But i have an error that goes like this....
"syntax error @ line 1: '/` unexpected"

May i know what syntax error it is?
I am actually trying to copy a file to /tmp ,through this routine, but why is this error??

Thanks
# 2  
Old 05-21-2008
In POSIX shells:
Code:
pct=`((100 * $dest) / $source )`
# use this instead
pct= $(( (100 * $dest) / $source ))

# 3  
Old 05-21-2008
Hi,

even the one you gave doenst seem to be working!!!!
I get an error like this,
"syntax error @ line 10 : '(' unexpected"
This is in reference to the pct=.....
# 4  
Old 05-21-2008
Maybe you are looking for

Code:
((pct=100*dest/source))

... if your shell supports that syntax.

Unfortunately, the division is done using integer arithmetic, so you don't get a very precise result.

Further down, you also have a syntax error where you try to increment dest

Code:
((dest=dest+1))

You've copied the original rather imprecisely; you're not supposed to run the cp inside the while loop.

The loop appears to estimate that the copying rate will be one byte per second, which seems rather pessimistic.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Syntax error in code snippet

Hello, I am attaching a code snippet. Some of the variables are set in earlier code like count, arrays harr1, harr2, barr1 and barr2. The code below gives syntax errors. I am very new to Bash. for (( i=0; i<=$(( $count -1 )); i++ )) do #Now read the element at barr2 location i. Also find... (2 Replies)
Discussion started by: ngabrani
2 Replies

2. Shell Programming and Scripting

auto-generating assembly code by variables found by script

Hi everybody I'm working on a list of registers(flip-flops to be exact), now i need to extract some value from this list and use them as arguments to pass them to some assembly code for example i have: 118 chain79 MASTER (FF-LE) FFFF 1975829 /TCK F FD1TQHVTT1 ... (1 Reply)
Discussion started by: Behrouzx77
1 Replies

3. Programming

this code for addind polynomials using linked lists showed segmentation error..any help pls..

the error occurs in the function() "add" used... #include<stdio.h> #include<malloc.h> struct node { int exp; int coef; struct node * link; }; struct node * create_list(struct node *,int,int); void display(struct node *); struct node * add(struct node *,struct node *); ... (3 Replies)
Discussion started by: mscoder
3 Replies

4. Solaris

Error generating ssh-keygen

I'm trying to generate this key but getting an error "file not found" Here is the command: # ssh-keygen -t dsa Generating public/private dsa key pair. Enter file in which to save the key (//.ssh/id_dsa): /export/home/bartadm/.ssh/id_dsa Enter passphrase (empty for no passphrase): Enter... (2 Replies)
Discussion started by: Kjons76
2 Replies

5. Shell Programming and Scripting

Need help line 35: syntax error: unexpected end of file only 34 lines of code

I am not sure what I am doing wrong here, I did some research and only confused myself further. Any help would be greatly appreciated. I need to make this work for work tomorrow. There are only 34 lines of code in this script, yet its complaining about line 35 Here is the code: ... (7 Replies)
Discussion started by: BkontheShell718
7 Replies

6. Programming

Syntax error in tcl/tk code

Hi All, I have written a code in tcl which is supposed to open an GUI in which numbers will be entered & after performing selected operation it wil show a result. #!/usr/local/bin/wish #package require Tk #global opr proc DoOperation {} { global opr set fstno set scdno set result ... (2 Replies)
Discussion started by: milindb
2 Replies

7. Solaris

Generating a generic incremental code

Hi Gurus, I have several Solaris systems (say system a, system b,system c) which will connect to a windows system (system Z) using SFTP session. I have a 'txt' file on System Z , which has a simple numeric value on it(say 1) , If I have to increment this number with 1 (1+1 =2) irrespective of... (3 Replies)
Discussion started by: ramky79
3 Replies

8. Shell Programming and Scripting

Pls correct the "if" syntax

Iam a learner of UNIX. Fortunately I got this site. I want to check the file for its existance. if echo " Not present" else echo "Present" fi The above code is working fine. But I also want to check for the files which are compressed. I tried the following code and it is not... (5 Replies)
Discussion started by: ganapati
5 Replies

9. UNIX for Dummies Questions & Answers

0403-057 Syntax error at line 70. pls help

Hi All, I got a script from one of the unix forums for reporting on filesystem usage and wanted to use it but it keeps giving me the following error. 0403-057 Syntax error at line 70 The script is shown below. Pls help as I am new to UNIX. # set -x # D I S K S P A C E . S H # #... (2 Replies)
Discussion started by: OMONI
2 Replies
Login or Register to Ask a Question