On Tue, Aug 18, 2009 at 3:52 PM, Mark J. Reed <markjr...@gmail.com> wrote:

> On Tue, Aug 18, 2009 at 9:26 AM, Jan Ingvoldstad<frett...@gmail.com>
> wrote:
> > You think it's a bug that PWD="/etc" doesn't change your working
> directory
> > to /etc in bash?
> >
> > Please tell me you're joking.
>
> It's not that unreasonable.


I disagree, and I think I've explained why, and perhaps we won't get much
further.

But see below.


> But USER isn't even a shell-maintained variable.  It's set by login();
> the shell just inherits it.  A better example would be UID - which is
> readonly.
>

I'm not sure what you mean by a "shell-maintained variable".

As for $UID being read-only, that's a bashism. There's nothing inherent
about $UID that makes it read-only.

In a POSIX shell, you get this:

$ ksh --version
  version         sh (AT&T Research) 1993-12-28 s+
$ echo $UID $USER
501 jani
$ USER=root
$ UID=1000
$ echo $UID $USER
1000 root

csh is no different:

j...@krakas ~ >csh
[krakas:~] root% echo $USER
root
[krakas:~] root% set USER=foo
[krakas:~] root% echo $USER
foo
[krakas:~] root% echo $UID
501
[krakas:~] root% set UID=1000
[krakas:~] root% echo $UID
1000

bash in POSIX mode agrees:

j...@krakas ~ >bash --posix
j...@krakas ~ >echo $UID
501
j...@krakas ~ >UID=1000
j...@krakas ~ >echo $UID
1000

Even Perl 5 lets me change it:

j...@krakas ~ >perl --version|grep v5
This is perl, v5.8.9 built for darwin-2level
j...@krakas ~ >perl -e 'print "$ENV{UID}\n"; $ENV{UID}=1000; print
"$ENV{UID}\n";'
501
1000

-- 
Jan

Reply via email to