Handling whitespaces in the name of a ZFS dataset in a shell script
Not splitting at spaces
bash's for
loop splits the argument at all whitespace characters by default. You could somehow escape each line - or simply switch to another delimiter character. cut
will return one value per line, so there's a newline in between which we can choose.
Watch out for the double quotes in zfs get all
, so each $dataset
doesn't get split up, too.
#!/bin/bash
IFS=$'\n'
for dataset in `zfs list -H | cut -f 1`
do
zfs get all "$dataset"
done
Resetting IFS
Afterwards, you might want to reset IFS
to the value before, store it to some temporary variable.
OLD_IFS=$IFS
# the whitespaces-sensitive lines
IFS=$OLD_IFS