tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: interactive shell detection in shrc
Hello.
Greg A. Woods wrote in
<m1stwmt-0036s2C@more.local>:
|At Tue, 24 Sep 2024 00:56:40 +0200, Steffen Nurpmeso <steffen%sdaoden.eu@localhost> \
|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?
Pfffffh .. likely because i wanted to use aliases under some
conditions? Unforunately history ends in 2015, where i resorted
my entire configuration, and moved it all to git, i think.
(There is home.attic in the first commit, with .cvsrc and .hgrc.)
This could be the answer, as this file includes things as here
[ -f "${HOME}/.${OSTYPE}.alias" ] && . "${HOME}/.${OSTYPE}.alias"
(by then, ie, still ${}), and in nbsd5/home/.netbsd.alias i see
___aa s-patch 'patch -E --version-control numbered -p1'
___a s-patch-utc 'echo NetBSD patch(1) does not support UTC switch'
Ie that file creates aliases even if alias(1) is unsupported:
# Aliases are a bit complicated since some shells don't have support for
# them - in that case, just use shell functions!
# Set them just like, e.g.:
# ___a s-calendar '(cd && calendar)'
# ___aa s-cc '${CC} ${CFLAGS}'
# Note: don't use `command -V' instead of type(1), since Heirloom sh(1)
# will falsely report availability of alias(1), then
if [ ${___SHTYPE} -ne ${___SHTYPE_NONE} ] || \
( type alias | grep builtin ) >/dev/null 2>&1; then
___a() { alias "${1}"="${2}"; }
___aa() { alias "${1}"="${2}"; }
___ua() { unalias "${1}"; }
else
echo
echo ' *No alias support, aliases will be shell functions!*'
___a() {
fn=`echo ${1} | tr '.-' '__'` ex=$2
[ "${1}" != "${fn}" ] && echo " ${1} -> ${fn}"
eval ${fn}'() { '${ex}' ; }'
}
___aa() {
fn=`echo ${1} | tr '.-' '__'` ex=$2
[ "${1}" != "${fn}" ] && echo " ${1} -> ${fn}"
eval ${fn}'() { '${ex}' ${@+"${@}"} ; }'
}
___ua() { :; }
fi
I see ___ua() could do unset, could it.
|I do note the following from the bosh(1) manual:
|
| ... POSIX requires that job control is auto-enabled for
| interactive shells ...
|
|But I'm pretty sure the key word there is "interactive", which will by
|definition also mean they have 'i' in $-.
|
|
|For what it's worth I the original Bourne shell (as supplied in pkgsrc
|shells/heirloom-sh) does not put 'i' in $- (ever).
..ok. Ok, the last time i see anything Heirloomish here is the
mentioned web42
commit 747fdd220f973da357c18bf5a613145e8c90c195
Author: Steffen (Daode) Nurpmeso <steffen%sdaoden.eu@localhost>
AuthorDate: 2012-12-17 12:16:23 +0100
Commit: Steffen (Daode) Nurpmeso <steffen%sdaoden.eu@localhost>
CommitDate: 2012-12-17 17:47:16 +0100
test.sh: fix for Heirloom sh(1) plus..
Even though ":>file" works for Heirloom sh(1), even in a function
etc., the S-Web42 test.sh fails to run because ":>file" does not
work reliable (rejects to overwrite files).
I got sick after an hour and simply replaced the ":>" with
printf(1), which always works.
While there classify the filenames as being located in the
current directory, just to avoid possible problems with
shells that do not like unqualified paths.
s/reliable/reliably/ etc. (And will be changed to "> FILE" at
times.) Yes, i surely left it because of this, after loosing
confidence in that thing. (I have also left mksh after
i discovered a bug that made the entire machinery look suspicious
to me (and Thorsten answered something like "so it may be").) It
is not so weird today, with all the filesystem snapshots and such,
but by that time i still was using daily incremental plus weekly
incremental plus monthly complete backups, and such.
|The enhanced Bourne shells, aka the Schily Bourne Shells, shells/bosh
|and shells/pbosh, similarly do not have 'i' in $- while sourcing
|~/.profile, but they do adjust $- after ~/.profile has been sourced.
Jörg has seen this file (and an included alias thing) and was
amused. I have never said i am a good (shell) programmer, let
alone by that time. (I only have some "light" moments at times,
that much i would agree with, but rather not regarding shell, and
anyway accompanied with plenty of the opposite.)
|Since they all derive from the same parent I guess the fact they share
|this quality should not be too surprising.
|
|To work around this I do the following:
|
| _interactive=false
| case "$-" in
| *i*)
| _interactive=true
| ;;
| esac
| case "$0" in
| -*)
| _interactive=true
| ;;
| esac
| if ${_interactive}; then
|: ... do interactive setup
| else
|: ... do script-mode setup
| fi
| unset _interactive
This looks very much interesting, except that i would insist on
being afraid on that "if EXPANSION" thing. I mean, i know, in
CRUX Linux /etc/rc also comes with
# Load console keymap
if [ "$KEYMAP" ]; then
but that file has never seen anything but bash in the two decades
or so it exists.
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" , $3 , 4= "$4" , $4 , 5= "$5" , $5 , 6= "$6" , $6 , '*=' "$*" , $* , '@=' "$@" , $@
}
set -- '' '' ''
a "$*"$* $*
...
-1,1= / ,2=/,3=/,4=/,5=/,6=/,*= / ,@= ,$
^
there is this space, whereas
-1,1= , , 2= , , 3= , , 4= , , 5= , , 6= , , *= , , @= ,$
^
here there is it not (that is bash, but dash ditto).
+1,1= /,2=/,3=/,4=/,5=/,6=/,*= /,@= ,$
+1,1= , , 2= , , 3= , , 4= , , 5= , , 6= , , *= , , @= , $
This is my MUA, and it currently is still wrong (anyway).
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)
Home |
Main Index |
Thread Index |
Old Index