4 of 5 More context, and the result of an experiment based on the first answer.

Handling whitespaces in the name of a ZFS dataset in a shell script

I'd like to take output from two commands –

zpool list
zfs list

and for each found pool:

zpool get all nameofpool

and for each found file system:

zfs get all nameoffilesystem

Environment

#!/bin/sh

As background: I'm making local changes to script that's integral to OS X,

/usr/bin/sysdiagnose

which uses that shell and is always run with superuser privileges.

First experiment

Based on the example at #65 Remove all ZFS snapshots:

#!/bin/sh
for dataset in `zfs list -H | cut -f 1`
do
  zfs get all $dataset
done

That works, but not where there's a space in the name of the dataset. For example where the file system is zhandy/Pocket Time Machine the output includes:

cannot open 'zhandy/Pocket': dataset does not exist
cannot open 'Time': dataset does not exist
cannot open 'Machine': dataset does not exist

 Second experiment

Based on the first answer to this question – using IFS – and making the script more like Apple's:

#!/bin/sh
data_directory_path=~/Desktop
ECHO=/bin/echo
ZFS=/usr/sbin/zfs
ZPOOL=/usr/sbin/zpool
OLD_IFS=$IFS
# If there exists a zfs binary, get some ZFS-related information
if [ -f "${ZFS}" ]
then
    "${ECHO}" "Recording ZFS pool version information ..."
    "${ZPOOL}" upgrade &> ${data_directory_path}/zpool\ upgrade.txt
    "${ECHO}" "    listing all ZFS pools ..."
    "${ZPOOL}" list &> ${data_directory_path}/zpool\ list.txt
    "${ECHO}" "    detailed health status and verbose data error information ..."
    "${ZPOOL}" status -v &> ${data_directory_path}/zpool\ status.txt
    "${ECHO}" "    pools that are available but not currently imported"
    "${ZPOOL}" import &> ${data_directory_path}/zpool\ import.txt
    "${ECHO}" "Recording ZFS file system version information ..."
    "${ZFS}" upgrade &> ${data_directory_path}/zfs\ upgrade.txt
    "${ECHO}" "    listing all ZFS file systems ..."
    "${ZFS}" list &> ${data_directory_path}/zfs\ list.txt
    "${ECHO}" "    all properties of each file system "
    IFS=$'\n'
    for dataset in `zfs list -H | cut -f 1`
    do
        "${ZFS}" get all $dataset &> ${data_directory_path}/ZFS\ file\ system\ properties.txt
    done
    IFS=$OLD_IFS
    "${ECHO}" "Listing the contents of /dev/dsk"
    "${LS}" -@adel /Volumes &> ${data_directory_path}/ls-dev-dsk.txt
    "${ECHO}" "Listing the contents of /var/zfs/dsk"
    "${LS}" -@adel /Volumes &> ${data_directory_path}/ls-var-zfs-dsk.txt
fi

Amongst the resulting files, ZFS file system properties.txt lists properties for just one ZFS file system … a dataset with white space in its name, so we do seem closer to an answer, but not quite there yet.

The required result is properties for all ZFS file systems …