Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!mips!smsc.sony.com!dce From: dce@smsc.sony.com (David Elliott) Newsgroups: comp.unix.questions Subject: Re: Funny csh output? Message-ID: <1990Feb28.222329.3532@smsc.sony.com> Date: 28 Feb 90 22:23:29 GMT References: <6662@cps3xx.UUCP> <12251@smoke.BRL.MIL> <6669@cps3xx.UUCP> Reply-To: dce@Sony.COM (David Elliott) Organization: Sony Microsystems Corp. Lines: 106 In article <6669@cps3xx.UUCP> davisd@cpsvax.UUCP (Dug) writes: >In article <12251@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: >#In article <6662@cps3xx.UUCP> davisd@cpsvax.cps.msu.edu (Dug) writes: >#>% jobs | wc >#> 0 0 0 ># >#There are no suspended jobs in the shell that's running the pipeline >#(it's a subprocess of the one that printed the prompt). > >But it that's true then why can I redirect it to a file and have my >stopped jobs show up there? (i.e. jobs > test will result in "test" >having the correct output of jobs) Mainly because it's an easier problem to solve. With redirection of a builtin, all you have to do is to save the current file descriptor state, run the builtin, and then put it back. When you work with pipes, you have to fork new subshells to run each piece. If you take a look at the csh source (sh.h, specifically), you'll find that csh starts out by saving the standard file descriptors so that it can handle redirection for builtins easily. It is interesting to note that some builtins do work with pipes. History, for example, does just what you'd expect with a pipe (in most cases -- on the machine I'm using right now, history | more doesn't work correctly). If you do need to send the output of jobs through a pipe, your best bet is to just use a temp file. In my .cshrc, I have the following alias which allows me to use the output of "jobs -l" to send me to the working directory for any given job: alias jd 'jobs -l >! $home/.jobdir ; eval `jobdir < $home/.jobdir`' The jobdir command is a simple shell script: #!/bin/sh # # jobdir - print a command to cd to the directory where the named job # is executing. The argument can be +, -, or a 1- or 2-digit # number. No argument is the same as '+'. # PATH=/bin:/usr/bin:/usr/ucb # # Global variables # Myname=`basename "$0"` main() { case "$1" in ""|+) dir=`getplus` ;; -) dir=`getminus` ;; [0-9]|[0-9][0-9]) dir=`getnum "$1"` ;; *) echo "echo bad directory" exit ;; esac case "$dir" in "") echo "cd ." ;; *) echo "cd $dir" ;; esac exit 0 } getplus() { sed -n 's/^[^ ]* +.*(wd: \(.*\))$/\1/p' } getminus() { sed -n 's/^[^ ]* -.*(wd: \(.*\))$/\1/p' } getnum() { sed -n 's/^\['"$1"'\].*(wd: \(.*\))$/\1/p' } main ${1+"$@"} exit 0 -- David Elliott dce@smsc.sony.com | ...!{uunet,mips}!sonyusa!dce (408)944-4073 "...it becomes natural, like a third sense." -- Homer Simpson