I have such a function…
function size {
export FILENAME=$1
export SIZE=$(du -sb $FILENAME | awk '{ print $1 }')
awk 'BEGIN{x = ENVIRON["SIZE"]
split("Byte KiloByte MegaByte GigaByte TeraByte PetaByte ExaByte ZettaByte YottaByte", type)
for(i=8; y < 1; i--)
y = x / (2**(10*i))
print y " " type[i+2]
}'
}
size “/home/foo.bar” # 1 MegaByte
how can I insert: print y ” ” type[i+2]
to variable: SIZE_FILE ?
test: SIZE_FILE=${print y ” ” type[i+2]} # error 🙁
Thank you very much
The $( expr ) construct will save the result of evaluating “expr” in to a variable:
You can also use backticks, but I think the $() is more readable:
So for your scripts, you’ll use: