我的文件系统如下所示
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
答案 0 :(得分:0)
你不能在等号周围放置空格,你需要反引用将命令的结果放在一个变量中。
试试这个:
extract($varianti);
var_dump($pa_colore);
答案 1 :(得分: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'这里
How can I *only* get the number of bytes available on a disk in bash?