work around ksh feature in other shells

work around ksh feature in other shells

Post by Ken Pizzi » Tue, 02 Nov 1999 04:00:00




Quote:>echo foo bar baz | read junk *schmutz

>doesn't work outside of ksh.

>How can I do something analogous (where the first part of the pipeline
>is a rather * command) w/o using a temp file?

Depends on what is permissible.

One way:
  set -- `command`
  junk=$1 crap=$2 schmutz=$3

Another (bash syntax):
  words=(`command`)
  junk=${words[0]} crap=${words[1]} schmutz=${words[2]}

Another:
  word=0
  for x in `command`; do
    case $word in
     0) junk=$x ;;
     1) crap=$x ;;
     2) schmutz=$x ;;
    esac
    word=`expr $word + 1`
  done

Another (violating your prohibition on temp files):
  command >tmp.$$
  exec 3<&1 <tmp.$$
  rm -f tmp.$$
  read junk *schmutz
  exec 1<&3 3>&-

The possibilites abound...

                --Ken Pizzini

 
 
 

work around ksh feature in other shells

Post by John Savag » Wed, 10 Nov 1999 04:00:00



Quote:>Ksh executes the last part of a pipeline in the current shell; other
>shells do not.

>Upshot is:

>echo foo bar baz | read junk *schmutz

>doesn't work outside of ksh.

read a b c <<+
`command`
+

Oops, what was that you said about not using a temp file? (Behind the
scenes, the system creates a /tmp file for here documents like this.)
--
John Savage            (for email, replace "ks" with "k" and delete "n")