mogabr
July 24, 2011, 7:44pm
1
hello
every time i run the following code
for val in fileX fileY fileZ
do
$val=`ls -l $val | awk '{print $5}'`
done
i got error message command not found , i tried to add ' and " but nothing works
its only worked wen remove $val=
but i want the name of the file and the value
thanks to advice
agama
July 24, 2011, 9:24pm
2
I think what you want is something like this:
info="$val $(ls -l $val | awk '{print $5}')"
which will assign the current file name and then the file size into the variable info.
Aia
July 24, 2011, 9:29pm
3
Do as a favor and post what you are trying to accomplish.
The example lines are broken at many levels and figuring out what you are trying to do is not productive.
In any case, to answer your question. $val=`ls -l $val | awk '{print $5}'`
Remove the dereferencing $ in red.
mogabr
July 25, 2011, 4:22am
4
agama:
I think what you want is something like this:
info="$val $(ls -l $val | awk '{print $5}')"
which will assign the current file name and then the file size into the variable info.
hello
i want the out put like this
fileX=54831 (the number is the file size)
fileY=75778
fileZ=457455
---------- Post updated at 01:22 AM ---------- Previous update was at 01:22 AM ----------
aia:
Do as a favor and post what you are trying to accomplish.
The example lines are broken at many levels and figuring out what you are trying to do is not productive.
In any case, to answer your question. $val=`ls -l $val | awk '{print $5}'`
Remove the dereferencing $ in red.
hello
i want the out put like this
fileX=54831 (the number is the file size)
fileY=75778
fileZ=457455
yazu
July 25, 2011, 4:26am
5
Try:
for val in fileX fileY fileZ
do
size=`ls -l val | awk '{print $5}'`
echo "$val=$size"
done
mogabr:
hello
i want the out put like this
fileX=54831 (the number is the file size)
fileY=75778
fileZ=457455
---------- Post updated at 01:22 AM ---------- Previous update was at 01:22 AM ----------
hello
i want the out put like this
fileX=54831 (the number is the file size)
fileY=75778
fileZ=457455
# for val in fileX fileY fileZ; do echo $val=$(stat -c %s $val) ; done
# for val in fileX fileY fileZ; do echo $val=`ls -l $val|awk '{print $5}'`; done
If you prefer awk then..
ls -l file? | awk '{print $NF"="$5}'
mogabr
July 25, 2011, 9:36am
8
its works good ... thanks for your help
it does not work..must add a `$` to before the val
size=`ls -l $val | awk '{print $5}'`
1 Like
yazu
July 25, 2011, 11:59pm
10
@ygemici
Yes, you are right. It was so simple so I didn't test my script before posting. My mistake.