-1

我的文件系统如下

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-rootvol
                       20G  3.7G   15G  20% /
tmpfs                  71G  8.0K   71G   1% /dev/shm

我的代码如下:

varone = df -h | awk ' {print $1 }'
vartwo = df -h | awk ' NR == 2 {print $2","$3","$4","$5","$6 }'
echo "$varone $vartwo" >> /home/jeevagan/test_scripts/sizes/excel.csv

我想将“ df -h”导出到 csv 文件中。为什么我$1在一个变量中单独打印意味着,“ df -h”输出中有空格。我希望它打印在一行中。

当我运行脚本时,它会抛出一个错误,如

varone: command not found

vartwo: command not found

4

2 回答 2

0

如果您只想捕获 df -h

varOne=`df -h -P| awk '{print $1","$2","$3","$4","$5","$6 }'`
echo  "$varOne" >> /home/jeevagan/test_scripts/sizes/excel.csv

在此处阅读有关“P”的信息

我怎样才能 *only* 在 bash 中获取磁盘上可用的字节数?

于 2016-08-03T10:45:11.127 回答
0

您不能在等号周围放置空格,并且您需要使用反引号将命令的结果放入变量中。

尝试这个:

varone=`df -h | awk ' {print $1 }'`
vartwo=`df -h | awk ' NR == 2 {print $2","$3","$4","$5","$6 }'`
echo "$varone $vartwo" >> /home/jeevagan/test_scripts/sizes/excel.csv
于 2016-08-03T10:17:09.787 回答