[lug] Subshell behavior with potato bash?
socket at peakpeak.com
socket at peakpeak.com
Fri Jan 21 08:29:39 MST 2000
Tkil <tkil at scrye.com> writes:
> Chris> f="$(who | grep $(tty | sed s./dev/..))"
>
> hm. what are you trying to use this for? it doesn't seem too much
> more informative than just "tty" by itself. further, "last -1" might
> be more what you're looking for. or actually:
>
> last -1 `id -un`
>
> maybe.
>
> then again, i don't know what you're trying to do. :)
Well, the *full* story behind this is that I decided I wanted to learn
something real about shells last summer from a friend of mine, Aaron,
who is actually on this list and who posted yesterday with a fix for
me. The line in question is part of a block of code used to set and
export a REMOTEHOST variable. Unless he got it from somewhere else,
I'm assuming he wrote this block, and I haven't changed it at all,
except (as I read it now, in fact) to specify a usable case for the
domain. At least, that's how I'm reading it so far.
With the fix he gave me yesterday, it looks something like this:
f=($tty); f="$(who | grep "${f#/dev/}")"
if echo "$f" | grep -q "("; then
REMOTEHOST="$(echo "$f" | sed 's/^.*(\([a-zA-Z0-9_.-]*\)).*$/\1/')"
case "$REMOTEHOST" in
*.colorado.*)
REMOTEHOST="$(echo "$REMOTEHOST" | sed 's/^\([^.]*\)[.]colorado[.].*$/\1/')"
export REMOTEHOST
;;
esac
export REMOTEHOST
fi
I changed the case from a specific *.domain.* that Aaron was once
associated with to *.colorado.*, (though in my case, it would make
more sense to do *.colorado.edu, once I figure out just how to avoid
breaking that sed bit, since the university isn't likely to change
away from .edu, so I would definitely want to make sure I'm working
within colorado.edu when I need to know about REMOTEHOST...)
I suppose it's useful occasionally for things like this to break
occasionally, to remind me of my goal to learn about shells. It's
about time I went through some of this stuff.
Thanks.
--
Chris Riddoch socket at peakpeak.com
Will provide pseudo-insightful commentary for food
http://www.peakpeak.com/~socket
GPG key 1024D/234551DC 1999-07-15 Chris Riddoch <socket at peakpeak.com>
Key fingerprint = 7AAF 5815 837C 070C 6C70 8A15 EFD2 5860 2345 51DC
More information about the LUG
mailing list