[SLUG] quoting

From: Eben King (eben1@tampabay.rr.com)
Date: Fri Dec 16 2005 - 16:07:38 EST


OK, I'l having a quoting problem. Not people taking things out of context,
or using quotes without attribution, shell quoting. What I want is the "du
-sh"-style output, only sorted by size. The only way I can see to do that
is to get the "du -s"-style output, sort it, trim off the size, and call "du
-sh' on each one. Rather inefficient, but I don't see a better way.
(Sorting "du -sh"'s output will put "100M" before "200K".)

What I have is this:

#! /bin/bash
...
    case $1 in
        READABLE=human
        shift
    esac
...
case $READABLE in
...
    human)
    PP='cut -f 2- -d \ '
    set -x
esac

   du -s "$@" \
   | sort -$SORT_ARGS \
   | sed 's@ \./@ @' \
   | $PP ;;

Its output is:
[eben@pc eben]$ ddu -h /export/media/*
+ du -s /export/media/backgrounds /export/media/ferret-legging.txt
/export/media/images /export/media/midi /export/media/mod
/export/media/movie /export/media/mp3 /export/media/palette.64.gif
/export/media/palette.64.ppm /export/media/patterns
/export/media/root.cache.980907 /export/media/sounds /export/media/temp
+ sort -n
+ sed 's@ \./@ @'
+ cut -f 2- -d '\'
4 /export/media/palette.64.gif
4 /export/media/palette.64.ppm
4 /export/media/root.cache.980907
16 /export/media/ferret-legging.txt
442 /export/media/patterns
1413 /export/media/mod
16240 /export/media/midi
31731 /export/media/temp
159625 /export/media/sounds
422843 /export/media/backgrounds
1732338 /export/media/movie
4014387 /export/media/images
5605004 /export/media/mp3

It is ignoring the space in this case. I've tried putting the space
preceded by a backslash (in and out of $S), naked, in double quotes (ditto),
and in single quotes (ditto). I always get an error about -d needing a
single character; either that or it gets ignored.

What am I doing wrong, and what's the right way to do it? Thanks.

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar

Logic is a systematic method of coming to the wrong conclusion with confidence.

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:56:31 EDT