Hello.
Coming back to an old thread from September 2024, about shell word
aka field splitting ...
RVP wrote in
<66f9553f-7e86-97e5-2669-f3b7d7177...@sdf.org>:
|On Fri, 27 Sep 2024, Steffen Nurpmeso wrote:
|
|> Yes i am afraid of shell field splitting and expansion, and i do
|> not understand
Date:Thu, 10 Oct 2024 09:16:08 -0700
From:"Greg A. Woods"
Message-ID:
| As I wrote in my other message yesterday I've given up entirely on
| trying to test for interactivity without using $-.
Yes, I saw that, and I think that's the right approach.
| I have di
lso tested stdin and _stdout_ when
deciding if it was interactive or not. The change to test stderr must
have come from AT&T Ksh. I see that's done as early as ksh88e, for
example.
At Thu, 10 Oct 2024 13:21:16 +0700, Robert Elz wrote:
Subject: Re: interactive shell detection in shrc
>
At Wed, 09 Oct 2024 09:57:31 +0700, Robert Elz wrote:
Subject: Re: interactive shell detection in shrc
>
> But if the idea is to use just that to determine if a shell
> is interactive, as in:
>
> | When I decided this is what interactive means
> | all of the edge cases wen
Date:Fri, 04 Oct 2024 13:43:17 -0700
From:"Greg A. Woods"
Message-ID:
| To handle the second part of this rule we must compare $0 and $SHELL, as
| the presence of any operands upon invocation will have changed $0 to
| something other than $SHELL.
That's not st
Robert Elz wrote in
<1895.1728442...@jacaranda.noi.kre.to>:
|Date:Fri, 4 Oct 2024 07:53:59 -0700
|From:George Georgalis
|Message-ID:
|
||> test -t 0
||>
||> is reliable.
|
|It is, for what it is suppposed to do.
...
|and in the script if you do "test -t 0
Date:Fri, 4 Oct 2024 07:53:59 -0700
From:George Georgalis
Message-ID:
| > test -t 0
| >
| > is reliable.
It is, for what it is suppposed to do.
| Is there a case where this is not the solution?
To which problem exactly? If to determine whether stdin
(i
On Fri, Oct 4, 2024 at 1:43 PM Greg A. Woods wrote:
> At Mon, 30 Sep 2024 22:52:18 +0200, tlaro...@kergis.com wrote:
> Subject: Re: interactive shell detection in shrc
> >
> > But, if I'm not mistaken, the discussion was about testing if a shell
> > is interactive, t
At Mon, 30 Sep 2024 20:39:47 + (UTC), RVP wrote:
Subject: Re: interactive shell detection in shrc
>
> and also by programs which start a shell in a pty: xterm/script/tmux/...
> However, xterm _doesn't_ set SHELL if what was passed is not in /etc/shells:
That situation is also e
At Mon, 30 Sep 2024 22:52:18 +0200, tlaro...@kergis.com wrote:
Subject: Re: interactive shell detection in shrc
>
> But, if I'm not mistaken, the discussion was about testing if a shell
> is interactive, that is, "inheriting" whatever has been set and
> testing it.
Ind
On Fri, Oct 04, 2024 at 07:53:59AM -0700, George Georgalis wrote:
> On Mon, Sep 30, 2024 at 1:26?PM George Georgalis wrote:
>
> >
> > On Mon, Sep 30, 2024 at 1:09?PM wrote:
> >
> >> So how can the test be reliable in all circumstances?
> >>
> >
> > test -t 0
> >
> > is reliable.
> >
> > I use
>
On Mon, Sep 30, 2024 at 1:26 PM George Georgalis wrote:
>
> On Mon, Sep 30, 2024 at 1:09 PM wrote:
>
>> So how can the test be reliable in all circumstances?
>>
>
> test -t 0
>
> is reliable.
>
> I use
>
> tty -s || return 0
>
> to remind me what I'm testing for (same difference),
> and branch o
At Mon, 30 Sep 2024 21:59:49 +0200, wrote:
Subject: Re: interactive shell detection in shrc
>
> On Mon, Sep 30, 2024 at 12:14:44PM -0700, Greg A. Woods wrote:
> > > SHELL is set by ksh and not by sh (sh handles NETBSD_SHELL), if I'm
> > > not mistaken?
> >
>
On Tue, 1 Oct 2024, RVP wrote:
Ugly, but, works--after a fashion:
- Only for DIRs in the CWD.
- no `/' allowed in DIR.
- if CMD with the same name as DIR is found in $PATH, that will be executed.
(I tried defining a command_not_found_handle function but that doesn't
seem to work if the comm
On Tue, 1 Oct 2024, Rhialto wrote:
In bash, I use an alias '..' for 'cd ..', and '...' for 'cd ../..', and
a few levels more. It is a very poor approximation of the AmigaShell
feature where typing a directory name as a command does a 'cd' to that
directory. I wish (ba)sh had such a feature...
In bash, I use an alias '..' for 'cd ..', and '...' for 'cd ../..', and
a few levels more. It is a very poor approximation of the AmigaShell
feature where typing a directory name as a command does a 'cd' to that
directory. I wish (ba)sh had such a feature... (I tried defining a
command_not_found_ha
On Mon, Sep 30, 2024 at 1:09 PM wrote:
> So how can the test be reliable in all circumstances?
>
test -t 0
is reliable.
I use
tty -s || return 0
to remind me what I'm testing for (same difference),
and branch out of .profile for not interactive sessions.
--
George Georgalis, (415) 894-271
RVP wrote in
:
|On Mon, 30 Sep 2024, tlaro...@kergis.com wrote:
|> But, if I'm not mistaken, the discussion was about testing if a shell
|> is interactive, that is, "inheriting" whatever has been set and
|> testing it. Since SHELL is not set by all login programs (your
|> example of xterm) an
On Mon, 30 Sep 2024, tlaro...@kergis.com wrote:
But, if I'm not mistaken, the discussion was about testing if a shell
is interactive, that is, "inheriting" whatever has been set and
testing it. Since SHELL is not set by all login programs (your
example of xterm) and since the variable, if redefi
On Mon, Sep 30, 2024 at 08:39:47PM +, RVP wrote:
> [...]
> On Mon, 30 Sep 2024, tlaro...@kergis.com wrote:
>
> > What I mean is that if I'm under ksh, and then I switch to sh even
> > explicitely setting interactive :
> >
> > $ printenv
> >
> > _=/usr/bin/printenv
> > ...
> > SHELL=/bin/ksh
On Mon, 30 Sep 2024, Greg A. Woods wrote:
SHELL is set by ksh and not by sh (sh handles NETBSD_SHELL), if I'm
not mistaken?
login(1) sets $SHELL, [...]
and also by programs which start a shell in a pty: xterm/script/tmux/...
However, xterm _doesn't_ set SHELL if what was passed is not in /e
On Mon, Sep 30, 2024 at 12:14:44PM -0700, Greg A. Woods wrote:
> > SHELL is set by ksh and not by sh (sh handles NETBSD_SHELL), if I'm
> > not mistaken?
>
> login(1) sets $SHELL, and in the BSD world it has done so since 4.2 or
> before. In the AT&T Unix world it has done so since at least
> Sys
> SHELL is set by ksh and not by sh (sh handles NETBSD_SHELL), if I'm
> not mistaken?
login(1) sets $SHELL, and in the BSD world it has done so since 4.2 or
before. In the AT&T Unix world it has done so since at least
System III, aka UNIX 3.0.
IIRC in 7th Edition Research Unix since there was o
On Mon, 30 Sep 2024, Robert Elz wrote:
| This is _very_ surprising; esp. when /bin/sh doesn't allow chars.
| like `/' and `.' in the function name.
Huh?
sh $ a.v() echo I have a dot in my name
sh $ a.v
I have a dot in my name
Ah, that's right. It's FreeBSD's /bin/sh (and dash) which doesn
> But in general, no, there's probably not a lot of use for it, but nor
> is there any particular reason to add special case code to prohibit
> it.
I was thinking, most languages have names for functions and such, but
sh is one of the few languages in which a zero-length routine name is
even repre
Date:Sun, 29 Sep 2024 23:59:48 + (UTC)
From:RVP
Message-ID:
| This is _very_ surprising; esp. when /bin/sh doesn't allow chars.
| like `/' and `.' in the function name.
Huh?
sh $ a.v() echo I have a dot in my name
sh $ a.v
I have a dot in my name
You can
On Wed, 25 Sep 2024, Robert Elz wrote:
In NetBSD's sh you can actually do
''() { echo nothing; }
(where the function body can be anything of course), then the empty-string
command (as distinct from absent command) does exist, and works, but I would
not recommend this to anyone, it isn'
On Sat, Sep 28, 2024 at 10:55:06AM -0700, Greg A. Woods wrote:
>
> Well, I'll be. I don't remember ever using "test -t"! I think I must
> have skipped over it entirely all these years! So I now have:
>
> if [ -t 0 -a -t 2 -a "$0" = "$SHELL" ]; then
> _interactive=true
>
At Sat, 28 Sep 2024 05:35:02 +0700, Robert Elz wrote:
Subject: Re: interactive shell detection in shrc
>
> But any current POSIX compat sh should have 'i' in $- if it is interactive.
> That is required.
Ah, but only since Issue 8.
That does clarify things, but it's rath
Steffen Nurpmeso wrote in
<20240927224352.XbfXbbOA@steffen%sdaoden.eu>:
|Robert Elz wrote in
| <10279.1727476...@jacaranda.noi.kre.to>:
| ...
||| I guess to be entirely POSIX compatible my test should include:
|||
||| tty >/dev/null 2>&1 && tty <&1 >/dev/null 2>&1 &&
||
||The second of th
Robert Elz wrote in
<10279.1727476...@jacaranda.noi.kre.to>:
...
|| I guess to be entirely POSIX compatible my test should include:
||
|| tty >/dev/null 2>&1 && tty <&1 >/dev/null 2>&1 &&
|
|The second of those would need to be testing (the pre-redirected)
|stderr, not stdout, interactive
Date:Fri, 27 Sep 2024 13:48:17 -0700
From:"Greg A. Woods"
Message-ID:
| But that was my point! "m" is not in $- either!
That's very odd, and not 'j' (the old option letter, in some shells,
that is now 'm') either?
(That is, in a shell which supports job control
Greg A. Woods wrote in
:
|At Fri, 27 Sep 2024 07:14:46 +0700, Robert Elz wrote:
|Subject: Re: interactive shell detection in shrc
...
|Reading POSIX Issue 7 sh(1) just now I note the following text:
|
| If the -i option is present, or if there are no operands and the
| shell's sta
At Fri, 27 Sep 2024 07:14:46 +0700, Robert Elz wrote:
Subject: Re: interactive shell detection in shrc
>
> Date:Thu, 26 Sep 2024 15:16:39 -0700
> From:"Greg A. Woods"
> Message-ID:
>
> | I'm very curious: why did you include "
At Fri, 27 Sep 2024 01:32:34 +0200, Steffen Nurpmeso wrote:
Subject: Re: interactive shell detection in shrc
>
> Hello.
>
> Greg A. Woods wrote in :
> |At Tue, 24 Sep 2024 00:56:40 +0200, Steffen Nurpmeso \
> |wrote:
> |Subject: Re: interactive sh
Date:Fri, 27 Sep 2024 01:48:13 +0200
From:Steffen Nurpmeso
Message-ID: <20240926234813.hgDdmZkJ@steffen%sdaoden.eu>
| I changed it to (but tab indent; private credits to you..)
|
| if [ -z "$___SHRC" ]; then
| if [ "$-" != "${-%i*}" ] || [ "$-" != "${-%m
Steffen Nurpmeso wrote in
<20240926233234.MwKivWJi@steffen%sdaoden.eu>:
|Greg A. Woods wrote in
| :
||At Tue, 24 Sep 2024 00:56:40 +0200, Steffen Nurpmeso \
...
||To work around this I do the following:
||
|| _interactive=false
|| case "$-" in
|| *i*)
|| _interactive=true
|| ;;
|| e
Hello.
Greg A. Woods wrote in
:
|At Tue, 24 Sep 2024 00:56:40 +0200, Steffen Nurpmeso \
|wrote:
|Subject: Re: interactive shell detection in shrc
|>
|> case ${-} in
|> *i*|*m*) # {{{
|> ...
|> esac
|
|I'm very curious: why did you
Date:Fri, 27 Sep 2024 01:32:34 +0200
From:Steffen Nurpmeso
Message-ID: <20240926233234.MwKivWJi@steffen%sdaoden.eu>
| Yes i am afraid of shell field splitting and expansion, and i do
| not understand why eg
|
| a() {
| echo
$#,1="$1"/$1,2="$2"/$
On Fri, 27 Sep 2024, Steffen Nurpmeso wrote:
Yes i am afraid of shell field splitting and expansion, and i do
not understand why eg
a() {
echo
$#,1="$1"/$1,2="$2"/$2,3="$3"/$3,4="$4"/$4,5="$5"/$5,6="$6"/$6,'*'="$*"/$*,'@'="$@",$@
echo $#,1= "$1" , $1 , 2= "$2" , $2 , 3= "$3"
Date:Thu, 26 Sep 2024 15:16:39 -0700
From:"Greg A. Woods"
Message-ID:
| I'm very curious: why did you include "m" in that test?
I wondered about that as well. But I suspect you have
supplied the answer.
| I do note the following from the bosh(1) manual:
|
At Tue, 24 Sep 2024 00:56:40 +0200, Steffen Nurpmeso wrote:
Subject: Re: interactive shell detection in shrc
>
> case ${-} in
> *i*|*m*) # {{{
> ...
> esac
I'm very curious: why did you include "m" in that test?
I do note the fol
Robert Elz wrote in
<6599.1727248...@jacaranda.noi.kre.to>:
|Date:Tue, 24 Sep 2024 23:54:13 + (UTC)
|From:RVP
|Message-ID: <4d7cdca7-fcf4-8985-7c1d-79ef63125...@sdf.org>
|
|| On Tue, 24 Sep 2024, Steffen Nurpmeso wrote:
|
|I replied to Steffen's (pre-forwar
RVP wrote in
<4d7cdca7-fcf4-8985-7c1d-79ef63125...@sdf.org>:
|On Tue, 24 Sep 2024, Steffen Nurpmeso wrote:
|> Robert Elz wrote in
|> <7132.1727161...@jacaranda.noi.kre.to>:
|>|Date:Tue, 24 Sep 2024 00:56:40 +0200
|> [...]
|>| if $___SHRC
|>
|> Oh, i would be afraid of doing thi
Date:Wed, 25 Sep 2024 14:17:07 +0700
From:Robert Elz
Message-ID: <6599.1727248...@jacaranda.noi.kre.to>
| Not a syntax error, an execution error,
Sorry, saw your following message correcting that after I replied.
| In NetBSD's sh you can actually do
| ''()
Date:Tue, 24 Sep 2024 23:54:13 + (UTC)
From:RVP
Message-ID: <4d7cdca7-fcf4-8985-7c1d-79ef63125...@sdf.org>
| On Tue, 24 Sep 2024, Steffen Nurpmeso wrote:
I replied to Steffen's (pre-forwarded) message off list, but:
| Yes, this surprised me too. This test is
On Tue, 24 Sep 2024, RVP wrote:
| if "${___SHRC:-:}"
A syntax error of yours?
No, that becomes `if ":" ...' $___SHRC is undefined or empty. You need to
write it that way, else it's a syntax error.
Sorry, I meant to say a "command not found" error (when trying to execute an
empty string
On Tue, 24 Sep 2024, Steffen Nurpmeso wrote:
Robert Elz wrote in
<7132.1727161...@jacaranda.noi.kre.to>:
|Date:Tue, 24 Sep 2024 00:56:40 +0200
[...]
| if $___SHRC
Oh, i would be afraid of doing this implicit test. I no longer
have many shells around, not even as source code, so i w
--- Forwarded from Steffen Nurpmeso ---
Date: Tue, 24 Sep 2024 22:26:34 +0200
Author: Steffen Nurpmeso
From: Steffen Nurpmeso
To: Robert Elz
Cc: Valery Ushakov
Subject: Re: interactive shell detection in shrc
Message-ID: <20240924202634.-Z-0KGXP@steffen%sdaoden.eu>
Robert Elz wr
Robert Elz wrote in
<23334.1727160...@jacaranda.noi.kre.to>:
|Date:Tue, 24 Sep 2024 03:06:49 +0300
|From:Valery Ushakov
|Message-ID:
|
|| I also wanted to drop the ${1+"$@"} workaroud for the v7 shell bug
|| which I'm pretty sure we are not going to hit in this
Date:Tue, 24 Sep 2024 03:06:49 +0300
From:Valery Ushakov
Message-ID:
| I also wanted to drop the ${1+"$@"} workaroud for the v7 shell bug
| which I'm pretty sure we are not going to hit in this day and age on a
| NetBSD system, but I won't to get down that rabb
Date:Tue, 24 Sep 2024 00:56:40 +0200
From:Steffen Nurpmeso
Message-ID: <20240923225640.BZkYDiMv@steffen%sdaoden.eu>
| and then (in ~/.shrc)
|
| eval "___isinc=\$___SHRC$$"
| if [ -z "${___isinc}" ]; then
| eval "___SHRC${$}=YES"
| e
Valery Ushakov wrote in
:
|On Tue, Sep 24, 2024 at 00:06:22 +0700, Robert Elz wrote:
|
|> Date:Mon, 23 Sep 2024 12:16:10 +0300
|> From:Valery Ushakov
|> Message-ID:
|>
|>| I'd like to switch this to the "early return" style, something like
|>|
|>| # the res
On Tue, Sep 24, 2024 at 05:01:18 +0700, Robert Elz wrote:
> | sh .shrc allows you to check that .shrc has no failures, but you cannot
> | test how it affected the shell (as opposed to sourcing it).
>
> That's the point, to test what would happen if it were sourced,
> to prevent undesired acti
Date:Tue, 24 Sep 2024 00:10:24 +0300
From:Valery Ushakov
Message-ID:
| shrc is there to affect the state of a shell in a
| way that is visible in subsequent use of that same shell.
Of course.
| sh .shrc allows you to check that .shrc has no failures, but you
On Tue, Sep 24, 2024 at 00:06:22 +0700, Robert Elz wrote:
> Date:Mon, 23 Sep 2024 12:16:10 +0300
> From:Valery Ushakov
> Message-ID:
>
> | I'd like to switch this to the "early return" style, something like
> |
> | # the rest of the file is for interactive she
Date:Mon, 23 Sep 2024 12:16:10 +0300
From:Valery Ushakov
Message-ID:
| I'd like to switch this to the "early return" style, something like
|
| # the rest of the file is for interactive shells only
| case "$-" in *i*) ;; *) return ;; esac
I think the primary
Our skel files use
case "$-" in *i*)
# interactive mode settings go here
;;
esac
which, IMO, is horrible for readability/usability as it suggests that
you add your changes to your shrc nested inside a case.
I'd like to switch this to the "early return" style, something like
#
58 matches
Mail list logo