From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Paul Smith <paul@mad-scientist.net>
Cc: Andrey Voropaev <voropaev.andrey@gmail.com>, dash@vger.kernel.org
Subject: Re: Tests [ 0 -eq $UID ] don't work as in bash
Date: Wed, 7 Sep 2016 21:02:18 +0100 [thread overview]
Message-ID: <20160907200218.GA28963@chaz.gmail.com> (raw)
In-Reply-To: <1473263700.7265.3.camel@mad-scientist.net>
2016-09-07 11:55:00 -0400, Paul Smith:
> On Wed, 2016-09-07 at 16:44 +0200, Andrey Voropaev wrote:
> > if [ 0 -eq $UID ]
>
> The variable UID is not defined to be automatically set by the shell in
> POSIX; having it set is a bash extension. dash doesn't set it
> automatically for you.
>
> You'll have to set it yourself:
>
> UID=$(id -u)
>
> Also you should quote variable references, in general:
>
> if [ 0 -eq "$UID" ]
>
> Be sure that if your scripts rely on bash-isms you start them with
> #!/bin/bash and if you don't want them to rely on bash-isms, you start
> them with #!/bin/sh.
[...]
Note that both zsh and bash have it, both from the start, both
copied from tcsh ($uid in tcsh).
In zsh, you can also set UID (and USERNAME and EUID, and GID...)
to change your uid (assuming you have the permission to do so).
$ sudo zsh -c 'id; UID=1000; id; UID=0'
uid=0(root) gid=0(root) groups=0(root)
uid=1000(chazelas) gid=0(root) groups=0(root)
zsh:1: failed to change user ID: operation not permitted
In bash, UID is read-only.
--
Stephane
prev parent reply other threads:[~2016-09-07 20:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-07 14:44 Tests [ 0 -eq $UID ] don't work as in bash Andrey Voropaev
2016-09-07 15:55 ` Paul Smith
2016-09-07 20:02 ` Stephane Chazelas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160907200218.GA28963@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=dash@vger.kernel.org \
--cc=paul@mad-scientist.net \
--cc=voropaev.andrey@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).