I want to be able to add numbers under data and bss section out of the size information of a file in command line
./script.sh [file name]
So far I wrote my script as :
ExcPath=$1 #read file name from command line
Numberone= size $1 | $data #put data column into Numberone
Numbertwo= size $1 | $bss #put bss column into Numbertwo
sum=$(( $Numberone + $Numbertwo )) # calculate the sum of DATA and BSS
echo $sum
$data
and $bss
are variables that I assumed that it is how shell reads from column "data" and "bss"
output from size test
:
text data bss dec hexfile name
2231 600 8 2839 b17 test
Expected output after running my script:
608
How could I achieve this in Shell Script? What did I do wrong?
I suggest to use awk
for this job:
#!/bin/bash
size "$1" | awk 'NR==2{print $2+$3}' # in row 2 sum column 2 and 3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.