"Syntax Error sometimes due to corruption of variable value "


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "Syntax Error sometimes due to corruption of variable value "
# 1  
Old 10-12-2012
"Syntax Error sometimes due to corruption of variable value "

Hi ,

I have script as follows ,

#!/usr/bin/ksh -x

if [ `uname` = "Linux" ]
then
alias echo="echo -e"
fi
MAX_ENTRIES=1024

nb_of_entries=`echo "$list_of_entries" | wc -w`
# Set number of tables
eval nb_of_tables=\`expr `expr $nb_of_entries / $MAX_ENTRIES` + 1 \`
# Output the number of tables
echo $nb_of_tables


Here "list of entries" is list of PID's and we get the output as number of pids .
================


For this above part i get the following error ,

+ echo -e $' 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n 10\n 11\n 12\n 13\n 14\n 15\n 16\n 17\n 18\n 59\n 66\n 67\n 68\n 69\n 70\n 233\n 234\n 235\n 236\n 239\n 241\n 328\n 329\n 330\n 331\n 332\n 333\n 334\n 544\n 596\n 597\n 598\n 599\n 600\n 626\n 629\n 657\n 691\n 1414\n 4674\n 4676\n 4677\n 4678\n 4718\n 4720\n 5060\n 5062\n 5094\n 5096\n 5119\n 5122\n 5134\n 5155\n 5184\n 5223\n 5242\n 5253\n 5257\n 5291\n 5329\n 5348\n 5366\n 5385\n 5396\n 5401\n 5416\n 5427\n 5439\n 5450\n 5461\n 5492\n 5513\n 5549\n 5550\n 5562\n 5564\n 5572\n 5577\n 5588\n 5660\n 5707\n 5770\n 5775\n 5776\n 5777\n 5779\n 5781\n 5783\n 5785\n 5883\n 5885\n 5886\n 5901\n 5904\n 5914\n 6046\n 6314\n 6316\n 6320\n 6332\n 6334\n 6336\n 6339\n 6347\n 6349\n 6351\n 6353\n 6362\n 6367\n 6399\n 6402\n 6404\n 6406\n 6408\n 6410\n 6412\n 6414\n 6416\n 6418\n 6420\n 6428\n 6431\n 6557\n 6568\n 6847\n 6850\n 6856\n 7354\n 7378\n 7405\n 7426\n 7448\n 7463\n 7472\n 7483\n 7541\n 7683\n 8119\n 8121\n 8323\n 8325\n 8326\n 8327\n15699\n21205\n21236\n25117'
+ wc -w
+ nb_of_entries=' 156'
+ expr 1 6 / 1024
expr: syntax error



Here 156 is replced with 1 6 which leads to syntax error . Please help me in finding what is making this corruption of variable value ?
# 2  
Old 10-12-2012
try with this one

Code:
 
nb_of_tables=$(($((nb_of_entries/MAX_ENTRIES)) + 1))

# 3  
Old 10-12-2012
i have tried this .

nb_of_tables=$(($((nb_of_entries/MAX_ENTRIES)) + 1))

and

nb_of_tables=\`expr `expr $nb_of_entries / $MAX_ENTRIES` + 1 \`


but as i told both works fine . only sometimes i face this problem . what makes the corruption ?
# 4  
Old 10-12-2012
why do you use eval ?

Code:
 
eval nb_of_tables=\`expr `expr $nb_of_entries / $MAX_ENTRIES` + 1 \`

# 5  
Old 10-12-2012
Here Actuall i have ,

list_of_entries=$1

numb_of_tables=`number_of_tables "$PID_LIST"`

number_of_tables ()
{
if [ `uname` = "Linux" ]
then
alias echo="echo -e"
fi
MAX_ENTRIES=1024

nb_of_entries=`echo "$list_of_entries" | wc -w`
# Set number of tables
eval nb_of_tables=\`expr `expr $nb_of_entries / $MAX_ENTRIES` + 1 \`
# Output the number of tables
echo $nb_of_tables

}

I think this answers why i have used eval , as we have

---------- Post updated at 04:02 AM ---------- Previous update was at 03:11 AM ----------

one more thing this happens only in certain directories.
# 6  
Old 10-12-2012
That's useless use of backticks..

And you should call function after defining it..Smilie

Code:
list_of_entries=$1

number_of_tables ()
{
if [ $(uname) = "Linux" ]
then
alias echo="echo -e"
fi
MAX_ENTRIES=1024

nb_of_entries=$(echo "$list_of_entries" | wc -w)
# Set number of tables
eval nb_of_tables=$(expr $(expr $nb_of_entries / $MAX_ENTRIES) + 1 )
# Output the number of tables
echo $nb_of_tables

}

numb_of_tables=$(number_of_tables "$PID_LIST")

# 7  
Old 10-12-2012
Quote:
I think this answers why i have used eval , as we have
It really doesn't... You've used it to sledgehammer in a solution but it was never necessary, and extremely seldom is. Which is a good thing because it's an enormous security hole.

Code:
set -- $list

echo "$# items"
X=$#
MAX=1024

let Z=X/MAX

echo "Z = $Z"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

Keep getting error "-bash: ./.profile_z2: line 52: syntax error: unexpected end of file"

#!/bin/bash #-------------------------------------------------------- # Setup prompt # Author Zeeshan Mirza # Data: 06-08-2017 #-------------------------------------------------------- if then . ./.profile_custom_pre fi umask 022 set -o vi export EDITOR=vi export VISUAL=vi... (3 Replies)
Discussion started by: getzeeshan
3 Replies

2. Ubuntu

What is solution for this error "tar: Exiting with failure status due to previous errors"?

Does anyone know what is solution for this error ?tar: Exiting with failure status due to previous errors from last 3 days I am trying to take backup of home/user directory getting again and again same error please anyone give me solution (8 Replies)
Discussion started by: Akshay Hegde
8 Replies

3. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

4. Homework & Coursework Questions

How to lclear "expr: syntax error" eventhough everything looks fine?

Hi All, As per my knowledge in unix, my code looks fine. But still I am getting error (expr:syntax error). Please help me to resolve this error. Script : PRE_LBNO=0 PRE_DATE=0 TOT_PAY=0 TOT_REM=0 TOTAL=1 for Record_Type in `cut -c 1 Inputt.dat` do if ; then CURR_LBNO=` cut -c... (6 Replies)
Discussion started by: lathanandhini
6 Replies

5. Shell Programming and Scripting

Syntax error near unexpected token `"Hit <ENTER> to continue:"'

the below code will search attr string inside makefile under the modelno on given path. echo "Enter model no for searching string inside makefile" read inputs2 #find /pools/home_unix/sapte/work/models/model/$inputs2 -name "makefile" | xargs grep "attr" \; #;;I am getting below error.... (7 Replies)
Discussion started by: lathigara
7 Replies

6. Shell Programming and Scripting

Bash (Ubuntu server): Syntax error: "|" unexpected in While-loop

Hello forum, I hope my problem is easy to solve for someone in here! My main task is to copy a large amount of imap-accounts from one server to another. There is a tool (Perl) called imapsync which does the job exellent. Unfortunately I'm only able to run it on one account at a time. After... (3 Replies)
Discussion started by: primaxx
3 Replies

7. Shell Programming and Scripting

Is this "Out of Memory!" error due to sort() of perl how to resolve it?

I am running a program written in perl script and it is stopped with "Out of memory!" error. This is very strange because at the time then the program is aborted, it only used 4GB RAM and there are still 30GB free physical memory left in the system. I check the perl script and found the program... (3 Replies)
Discussion started by: lilili07
3 Replies

8. Forum Support Area for Unregistered Users & Account Problems

Cannot register due to "spam" error message

Hi all, I am trying to register but it seems my IP address is being seen or black listed as a spam address. I get the following message: "Registration denied. Sorry, The UNIX and Linux Forums runs an active policy of not allowing spammers. Please contact us via by posting in this forum if... (0 Replies)
Discussion started by: codenjanod
0 Replies

9. Shell Programming and Scripting

ksh-script "arithmetic syntax error" comparing strings

Hi all, Iīve already searched the forum but canīt find what i am doing wrong. I am trying to compare two variables using ksh under red hat. The error I get is: -ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Discussion started by: old_mike
3 Replies

10. Shell Programming and Scripting

"syntax error at line 21 :'done' unexpected." error message"

I am trying to run the script bellow but its given me "syntax error at line 20 :'done' unexpected." error message" can someone check to see if the script is ok? and correct me pls. Today is my first day with scripting. Gurus should pls help out #!/bin/ksh # Purpose: Check to see if file... (3 Replies)
Discussion started by: ibroxy
3 Replies
Login or Register to Ask a Question