[英]BASH: Double quotes around part of array output?
I've spent way to long trying to figure this out, so I hope someone can shed some light on this. 我花了很长时间试图弄清楚这一点,所以我希望有人可以对此有所启发。
#!/bin/bash
HOSTNAME="`hostname`"
JSONFILE="${HOSTNAME}.json"
#####################
# FUNCTIONS #
#####################
function getfilesystems() {
count=0;
FILESYSTEMS=()
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for fs in `df -P | awk 'NR!=1'`; do
FILESYSTEMS+=("fs$count=${fs}")
(( count++ ))
done
echo "${FILESYSTEMS[@]}"
IFS=$SAVEIFS
}
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
jo -p serverdata="$(jo hostname=${HOSTNAME} reportdata="$(date)" storage="$(jo -p "$(getfilesystems)")")"
IFS=$SAVEIFS
I'm trying to focus on this part FILESYSTEMS+=("fs$count=${fs}")
我试图把重点放在这部分
FILESYSTEMS+=("fs$count=${fs}")
Right now, the output is this: 现在,输出是这样的:
'fs0=/dev/mapper/vg_rpidalappnfs-LogVol00 10190136 5486908 4178940 57% /' 'fs1=tmpfs 1962684 4 1962680 1% /dev/shm' 'fs2=/dev/sda1 194241 104145 79856 57% /boot'
It's almost what I want. 这几乎是我想要的。 What I need is this (see the quotes difference?):
我需要的是这个(请看引号的区别?):
fs0="/dev/mapper/vg_rpidalappnfs-LogVol00 10190136 5486908 4178940 57% /" fs1="tmpfs 1962684 4 1962680 1% /dev/shm" fs2="/dev/sda1 194241 104145 79856 57% /boot"
I've literally been trying to get this to work for about an hour and I just can't seem to get past this one part. 我一直在努力使它工作约一个小时,但我似乎无法超越这一部分。
The help is appreciated. 感谢您的帮助。
Escape the doublequote by a backslash: 用反斜杠转义双引号:
FILESYSTEMS+=("fs$count=\"${fs}")
But I fear you won't need the doublequotes in the output in the end, but I'm not familiar with jo
. 但是我担心您最终将不需要在输出中使用双引号,但是我对
jo
并不熟悉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.