[英]How do I read only the bss from size
I want to be able to add numbers under data and bss section out of the size information of a file in command line我希望能够在命令行中从文件的大小信息中添加数据和 bss 部分下的数字
./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" $data
和$bss
是我认为是 shell 从列“data”和“bss”读取的变量
output from size test
: 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?我如何在 Shell 脚本中实现这一点? What did I do wrong?我做错了什么?
I suggest to use awk
for this job:我建议使用awk
来完成这项工作:
#!/bin/bash
size "$1" | awk 'NR==2{print $2+$3}' # in row 2 sum column 2 and 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.