Quoth Karl Vogel on Thursday, 28 October 2010:
> >> On Thu, 28 Oct 2010 09:17:12 -0700, 
> >> Chip Camden <[email protected]> said:
> 
> C> Perhaps someone with more sh fu can transform the 'if' paragraph into a
> C> one-liner at least.  When I tried to do so, I got an unexpected ; error.
> 
>    Try this:
> 
>      #!/bin/sh
>      test $# -ge 1 && cat $@ | exec $0 && exit 0
> 
>      IFS=$'\n'
>      while read data; do
>        echo "$data"
>      done
>      exit 0
> 
>    Resetting IFS is only necessary if you want to preserve whitespace in
>    each line.  Putting $data in quotes prevents any shell metacharacters
>    from being expanded.
> 
> -- 
> Karl Vogel                      I don't speak for the USAF or my company
> Sign in a New York drugstore: "We dispense with accuracy"
> _______________________________________________
> [email protected] mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "[email protected]"


Much better than my latest version, which always invokes $0.  As an
alias:

alias inargs='[ $# -ge 1 ] && cat $@ | exec $0 && exit'

#!/bin/sh
inargs
while read data; do echo $data; done

-- 
Sterling (Chip) Camden    | [email protected] | 2048D/3A978E4F
http://camdensoftware.com | http://chipstips.com        | http://chipsquips.com

Attachment: pgpRPZvoCdAhv.pgp
Description: PGP signature

Reply via email to