Avatar of YZlat
YZlatFlag for United States of America asked on

Variable not found ksh script error

here is my code:

total_size=0
du -g $dir | temp_size=$( awk '{c+=$1};END { print c }')
echo $temp_size
$total_size += $temp_size

I get an error:

./myscript.ksh[7]: 0:  not found.

I also tried

total_size=0
du -g $dir | temp_size=$( awk '{c+=$1};END { print c }')
echo $temp_size
total_size += $temp_size

but that gave me almost the same error:

./myscript.ksh[7]: total_size:  not found.
Shell Scripting

Avatar of undefined
Last Comment
YZlat

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
radynski

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
YZlat

Now I get

 +=: 0403-058 Assignment requires an lvalue.

even thoug I did assign it the value of 0 initially
ASKER
YZlat

I also tried

let total_size = $(total_size  + $temp_size)

but that gives me 2 errors;

 0:  not found.
 =: 0403-058 Assignment requires an lvalue.
SOLUTION
YZlat

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ozo

Did you mean
total_size+=$temp_size
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
YZlat

part of the solution found myself