tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Fwd: Re: interactive shell detection in shrc
--- Forwarded from Steffen Nurpmeso <steffen%sdaoden.eu@localhost> ---
Date: Tue, 24 Sep 2024 22:26:34 +0200
Author: Steffen Nurpmeso <steffen%sdaoden.eu@localhost>
From: Steffen Nurpmeso <steffen%sdaoden.eu@localhost>
To: Robert Elz <kre%munnari.OZ.AU@localhost>
Cc: Valery Ushakov <uwe%stderr.spb.ru@localhost>
Subject: Re: interactive shell detection in shrc
Message-ID: <20240924202634.-Z-0KGXP@steffen%sdaoden.eu>
Robert Elz wrote in
<7132.1727161873%jacaranda.noi.kre.to@localhost>:
| Date: Tue, 24 Sep 2024 00:56:40 +0200
| From: Steffen Nurpmeso <steffen%sdaoden.eu@localhost>
| Message-ID: <20240923225640.BZkYDiMv@steffen%sdaoden.eu>
|
|| and then (in ~/.shrc)
||
|| eval "___isinc=\$___SHRC$$"
|| if [ -z "${___isinc}" ]; then
|| eval "___SHRC${$}=YES"
|| export ___SHRC${$}
|| case ${-} in
|| *i*|*m*) # {{{
|| ...
|| esac
|| fi
|| unset ___isinc
|
|Random suggestions, preceded by a question?
|
|Why are you exporting ___SHRC$$ ? As long as this shell
|continues running, there cannot be another process with the
|same $$ so the include guard cannot possibly have any effect
|anywhere else, and this shell doesn't need the variable to
|be exported to see it. By the time $$ is the same value in
|some other shell, you want the .shrc processed, don't you?
That is a too logical thinking for the above. I needed an include
guard, and it came out like that. What you say sounds right.
|Given that it doesn't need exporting, it also doesn't need
|the $$ in its name either, so
..yes?!..
| 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 would not
dare to do this.
| then
| ___SHRC=false
| case $- in
| *i*|*m*)
| # whatever
| ;;
| *)
| # whatever else
| ;;
| esac
| # common stuff for all cases
| fi
|
|If you insist on quoting the expansion in the first line,
|it needs to become:
|
| if "${___SHRC:-:}"
A syntax error of yours?
|even if you want too keep the $$ and export for some reason
|
| if eval "\$___SHRC$$"
| then
| eval "___SHRC$$=false"
| export "___SHRC$$"
| # etc
| fi
|
|with the similar variation if you want the ___SHRC$$ expansion
|quoted:
| if eval "\"\${___SHRC$$:-:}\""
|
You do it once again?
|kre
|
|ps: writing $$ (or any of the special params) as ${$} (etc)
|is really taking things a little far, unless you want a more
Yes, but i had a (pretty long, as in years) period of time when
i was doing this. It slowly comes to an end again. (Unless
necessity for separation arises.)
|complex expansion, like ${!:-$$} or something. It is even
|weirder when you write $$ in one place and ${$} in others
|(and use $- rather than ${-}). And of course using $# rather
Ja, the period came to an end, and i was not changing it all at
once. That is uncommon (for me), but the file is usually private
and never looked at.
I also seem to keep -- from the public files -- the syntax that
was used when it was written. However, looking at it, sometimes
there is a wild mixture of style in even the latest public thing,
the test of a DKIM signer. Well...
|than ${#} makes it clear that you want the number of set
|positional params, and not the length of something that you
|forgot to insert...
Hmmmm. Well, i do not often take lengths in the shell, and if
then mostly in a right-hand-side. Ok, i have looked, and i see
zero such constructs in all my public repositories as well as in
the misc.git that collects some stuff, and not in config.git.
$# is either argc, or used for patterns. But i guess the ${}
syntax will vanish over time.
You know, it is much easier with a German keyboard to not use *any
of* {}[], ie, programming on a German keyboard is asking for
arthritis, except for languages going for mostly $() -- i never
really thought about this but was "beetling" over it, so to say,
but then i had an english aka american keyboard for some years,
and it was pretty neat, and over that i came to that kind of
super-explicit shell syntax. And once the habit was adopted,
switching back to German keyboard did not change it for some
years; especially since on this laptop the "g" key stopped working
after a few weeks, and ever since i have to use
keycode 41 = f F g G g G
via my
[ -f ~/.${HOSTNAME}.xmodmaprc ] && xmodmap ~/.${HOSTNAME}.xmodmaprc
as well as
#@ /root/hosts/self/system-hook
if [ "${1}" = start ]; then
echo 'loadkeys: adjusting G key'
# dumpkeys/loadkeys
/usr/bin/loadkeys <<-_EOT
altgr keycode 33 = g
alt keycode 33 = g
shift alt keycode 33 = G
shift altgr keycode 33 = G
_EOT
fi
so that is a nice level of finger acrobatics anyway. Well.
Cool laptop, i love it. 512GB NVME disk, unbelievable.
--End of <7132.1727161873%jacaranda.noi.kre.to@localhost>
--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)
-- End forward <20240924202634.-Z-0KGXP@steffen%sdaoden.eu>
--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