Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"The Street finds its own uses for technology." -- William Gibson


devel / comp.unix.shell / Re: why bash in $0 ?

SubjectAuthor
* why bash in $0 ?Popping Mad
+* why bash in $0 ?Felix Palmen
|`* why bash in $0 ?Popping Mad
| +* why bash in $0 ?Keith Thompson
| |`* why bash in $0 ?Josef Moellers
| | `* why bash in $0 ?Janis Papanagnou
| |  +- why bash in $0 ?Josef_Möllers
| |  `* why bash in $0 ?Popping Mad
| |   +- why bash in $0 ?Josef_Möllers
| |   `- why bash in $0 ?Janis Papanagnou
| `* why bash in $0 ?Kaz Kylheku
|  +* why bash in $0 ?Felix Palmen
|  |`* why bash in $0 ?Popping Mad
|  | `* why bash in $0 ?Spiros Bousbouras
|  |  +* why bash in $0 ?Popping Mad
|  |  |`* why bash in $0 ?Felix Palmen
|  |  | `* why bash in $0 ?Popping Mad
|  |  |  +* why bash in $0 ?Felix Palmen
|  |  |  |`* why bash in $0 ?Helmut Waitzmann
|  |  |  | `* why bash in $0 ?Felix Palmen
|  |  |  |  `- why bash in $0 ?Helmut Waitzmann
|  |  |  +- why bash in $0 ?David W. Hodgins
|  |  |  `* why bash in $0 ?Keith Thompson
|  |  |   `- why bash in $0 ?Ruben Safir
|  |  `- dali_timer.sh (was: Re: why bash in $0 ?vallor
|  `* why bash in $0 ?Popping Mad
|   +* why bash in $0 ?Janis Papanagnou
|   |+- why bash in $0 ?Popping Mad
|   |`* why bash in $0 ?Popping Mad
|   | `- why bash in $0 ?Janis Papanagnou
|   `- why bash in $0 ?Kaz Kylheku
`* why bash in $0 ?Keith Thompson
 +* why bash in $0 ?Kenny McCormack
 |`- why bash in $0 ?Popping Mad
 +- why bash in $0 ?Popping Mad
 +- why bash in $0 ?Popping Mad
 `- why bash in $0 ?Popping Mad

Pages:12
Re: why bash in $0 ?

<u2e929$2m8$3@reader2.panix.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7007&group=comp.unix.shell#7007

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www.mrbrklyn.com!not-for-mail
From: rainbow@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Thu, 27 Apr 2023 12:49:09 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <u2e929$2m8$3@reader2.panix.com>
References: <u28b4u$6jn$1@reader2.panix.com>
<tnokhj-ep92.ln1@mail.home.palmen-it.de> <u29qed$5ud$1@reader2.panix.com>
<20230426094148.257@kylheku.com> <u2cv2v$j78$1@reader2.panix.com>
<u2dj39$1sl7i$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 27 Apr 2023 16:49:13 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="www.mrbrklyn.com:96.57.23.83";
logging-data="2760"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.10.0
Content-Language: en-US
In-Reply-To: <u2dj39$1sl7i$1@dont-email.me>
 by: Popping Mad - Thu, 27 Apr 2023 16:49 UTC

On 4/27/23 06:34, Janis Papanagnou wrote:
> This is how Unix shells work. It may make sense to take an hour or
> two to read about "command processing" in shells; the command line
> parsing process has a lot of steps that you shall be aware of if you
> intend to program in shell.

I've taken several classes in shell scriupting over the last 30 years,
and then I see something like this and it reminds me that I seem to
learn nothing.

Do you have a link to a resource?

Re: why bash in $0 ?

<u2e9av$2m8$4@reader2.panix.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7008&group=comp.unix.shell#7008

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www.mrbrklyn.com!not-for-mail
From: rainbow@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Thu, 27 Apr 2023 12:53:46 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <u2e9av$2m8$4@reader2.panix.com>
References: <u28b4u$6jn$1@reader2.panix.com>
<tnokhj-ep92.ln1@mail.home.palmen-it.de> <u29qed$5ud$1@reader2.panix.com>
<20230426094148.257@kylheku.com> <on2ohj-j0d1.ln1@mail.home.palmen-it.de>
<u2cv8u$j78$2@reader2.panix.com> <csyCpiemCIwzXzKDM@bongo-ra.co>
<u2e8o7$2m8$2@reader2.panix.com> <hglqhj-hk9.ln1@mail.home.palmen-it.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 27 Apr 2023 16:53:51 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="www.mrbrklyn.com:96.57.23.83";
logging-data="2760"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.10.0
Content-Language: en-US
In-Reply-To: <hglqhj-hk9.ln1@mail.home.palmen-it.de>
 by: Popping Mad - Thu, 27 Apr 2023 16:53 UTC

On 4/27/23 12:46, Felix Palmen wrote:
> For a script, the script is (logically) the executable, the shell just
> acts as an interpreter and will set $0 accordingly.

Right, but I would think though, that once #!/bin/bash is reached, that
a new shell executatible in formed in ram or on the stack with a new PID
and why should it be aware of what happened previously when the $0 is
expanded.

Do you see my point of confusion?

Reuvain

Re: why bash in $0 ?

<gcmqhj-j8a.ln1@mail.home.palmen-it.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7009&group=comp.unix.shell#7009

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: felix@palmen-it.de (Felix Palmen)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Thu, 27 Apr 2023 19:01:36 +0200
Organization: palmen-it.de
Lines: 26
Message-ID: <gcmqhj-j8a.ln1@mail.home.palmen-it.de>
References: <u28b4u$6jn$1@reader2.panix.com> <tnokhj-ep92.ln1@mail.home.palmen-it.de> <u29qed$5ud$1@reader2.panix.com> <20230426094148.257@kylheku.com> <on2ohj-j0d1.ln1@mail.home.palmen-it.de> <u2cv8u$j78$2@reader2.panix.com> <csyCpiemCIwzXzKDM@bongo-ra.co> <u2e8o7$2m8$2@reader2.panix.com> <hglqhj-hk9.ln1@mail.home.palmen-it.de> <u2e9av$2m8$4@reader2.panix.com>
Injection-Date: Thu, 27 Apr 2023 19:01:36 +0200
Injection-Info: dont-email.me; posting-host="9184936e274c74784ffdfaf2200b145b";
logging-data="2119995"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kWXkam5dWCmnTodnM3ral"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (FreeBSD/13.2-RELEASE (amd64)) tinews.pl/1.1.61
Cancel-Lock: sha256:F2C1Aq8iuPX2Km+JzV/95U07WQ7I370/eEhgOSsB7Dc=
sha1:1cHuhqRwm76YzaCqOqZDiYBU0bI=
X-PGP-Sig: GnuPG-v2 From,Newsgroups,Subject,Date,Injection-Date,Message-ID
iNUEARYIAH0WIQRpNhPVW79IN7ISOsxUreAGmHnyMQUCZEqqcF8UgAAAAAAuAChp
c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0Njkz
NjEzRDU1QkJGNDgzN0IyMTIzQUNDNTRBREUwMDY5ODc5RjIzMQAKCRBUreAGmHny
Mf7RAQD6PFjlcmN8nE76DSzA6Ej7pfLVAxA5KXC9GFFwdwkQugEAmL9lkKlhH8At
YQIPlC0/sWLTxpBq1BQDhW/u1kwSfgY=
=zabx
X-PGP-Hash: SHA256
X-PGP-Key: 693613D55BBF4837B2123ACC54ADE0069879F231
 by: Felix Palmen - Thu, 27 Apr 2023 17:01 UTC

* Popping Mad <rainbow@colition.gov>:
> Right, but I would think though, that once #!/bin/bash is reached, that
> a new shell executatible in formed in ram or on the stack with a new PID
> and why should it be aware of what happened previously when the $0 is
> expanded.

The shebang tells the OS which binary to run as the interpreter (feeding
the script and all its arguments to it). But keep in mind that argv[]
contains the WHOLE command line typed, so argv[0] is the command's name.

The exec() family of functions allows to specify argv[] and the actual
executable separately, and this is what happens when executing a script
that has a shebang. The binary named in the shebang is executed, but it
gets fed the original commandline in argv[], including the original
argv[0]. As a consequence, you will e.g. also see the script name in
'ps' output (and not the shell that's executing it).

Now, if you don't have a shebang but execute some script calling the
shell yourself, the shell will still know it's running as an interpreter
and therefore set $0 to argv[1] and so on.

--
Dipl.-Inform. Felix Palmen <felix@palmen-it.de> ,.//..........
{web} http://palmen-it.de {jabber} [see email] ,//palmen-it.de
{pgp public key} http://palmen-it.de/pub.txt // """""""""""
{pgp fingerprint} 6936 13D5 5BBF 4837 B212 3ACC 54AD E006 9879 F231

Re: why bash in $0 ?

<op.132nm8wya3w0dxdave@hodgins.homeip.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7010&group=comp.unix.shell#7010

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dwhodgins@nomail.afraid.org (David W. Hodgins)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Thu, 27 Apr 2023 14:14:58 -0400
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <op.132nm8wya3w0dxdave@hodgins.homeip.net>
References: <u28b4u$6jn$1@reader2.panix.com>
<tnokhj-ep92.ln1@mail.home.palmen-it.de> <u29qed$5ud$1@reader2.panix.com>
<20230426094148.257@kylheku.com> <on2ohj-j0d1.ln1@mail.home.palmen-it.de>
<u2cv8u$j78$2@reader2.panix.com> <csyCpiemCIwzXzKDM@bongo-ra.co>
<u2e8o7$2m8$2@reader2.panix.com> <hglqhj-hk9.ln1@mail.home.palmen-it.de>
<u2e9av$2m8$4@reader2.panix.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="575d0245c864ed37e04d6e7859fd14fd";
logging-data="2147650"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187ZJG8dJJ7LwFtz/A/cSeC48p6OzaZA10="
User-Agent: Opera Mail/12.16 (Linux)
Cancel-Lock: sha1:+EfuKYTdr65UHc7/xKsnpG8QnVc=
 by: David W. Hodgins - Thu, 27 Apr 2023 18:14 UTC

On Thu, 27 Apr 2023 12:53:46 -0400, Popping Mad <rainbow@colition.gov> wrote:
> Right, but I would think though, that once #!/bin/bash is reached, that
> a new shell executatible in formed in ram or on the stack with a new PID
> and why should it be aware of what happened previously when the $0 is
> expanded.
> Do you see my point of confusion?

Also note that the shebang is only used if the script is executed as a
command.

[dave@x3 bin]$ echo $0
/bin/bash

I'm running konsole under kde and as shown above, it's set to run bash.

[dave@x3 bin]$ cat echodollarzero
#!/bin/bash
echo $0

~/bin is in my path and ~/bin/echodollarzero is marked executable.

[dave@x3 bin]$ echodollarzero
/home/dave/bin/echodollarzero
[dave@x3 bin]$ ./echodollarzero
../echodollarzero

In both of the above, execve (see "man execve") uses the shebang to decide
which interpreter to use, and passes it the command line as entered as the
first parameter ($0).

[dave@x3 bin]$ ksh -c echodollarzero
/home/dave/bin/echodollarzero
[dave@x3 bin]$ strace -f ksh -c echodollarzero 2>&1|grep execve
execve("/usr/bin/ksh", ["ksh", "-c", "echodollarzero"], 0x7ffe2b383c28 /* 99 vars */) = 0
[pid 301725] execve("/home/dave/bin/echodollarzero", ["echodollarzero"], 0xce4e48 /* 103 vars */) = 0

In the above, the shebang is ignored. It's processed by ksh which sets $0
to the full path and filename of the script rather then just the command as
entered.

Regards, Dave Hodgins

Re: why bash in $0 ?

<u2ei2g$224rg$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7011&group=comp.unix.shell#7011

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Thu, 27 Apr 2023 21:22:55 +0200
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <u2ei2g$224rg$1@dont-email.me>
References: <u28b4u$6jn$1@reader2.panix.com>
<tnokhj-ep92.ln1@mail.home.palmen-it.de> <u29qed$5ud$1@reader2.panix.com>
<20230426094148.257@kylheku.com> <u2cv2v$j78$1@reader2.panix.com>
<u2dj39$1sl7i$1@dont-email.me> <u2e929$2m8$3@reader2.panix.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 27 Apr 2023 19:22:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9558a32a213d06b273defc1456ed798c";
logging-data="2167664"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tAM2V7G2lgAnbps4RP2wh"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:/oztsqvGO80jxLB5KEpnIdsryCw=
In-Reply-To: <u2e929$2m8$3@reader2.panix.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Thu, 27 Apr 2023 19:22 UTC

On 27.04.2023 18:49, Popping Mad wrote:
> On 4/27/23 06:34, Janis Papanagnou wrote:
>> This is how Unix shells work. It may make sense to take an hour or
>> two to read about "command processing" in shells; the command line
>> parsing process has a lot of steps that you shall be aware of if you
>> intend to program in shell.
>
> I've taken several classes in shell scriupting over the last 30 years,
> and then I see something like this and it reminds me that I seem to
> learn nothing.
>
> Do you have a link to a resource?

For links you have to use google and the mentioned keywords. Myself I
learned these things from books, e.g. Bolsky, Korn "The new Kornshell",
(1995, Prentice Hall); see chapter 11 ("command processing"). But you
probably will find also online resources if you search for "shells",
"command processing", and the 10+ steps taken, e.g. "tilde expansion",
"command substitution", "arithmetic expansion", "field splitting",
"pathname expansion", "path search", etc. (I'm not sure whether you
find these details also in the POSIX specification; might at least be
worth a try.[*]) A quick look into the bash or ksh man-pages seems
to provide also some information, but it's not well-structured and
provides no top-down overview, it seems. Below I appended from an old
ksh course - but it's written in German - the processing steps listed,
from these you may look up the details of the single steps in the
shell man pages.

Janis

[*]
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

===

Die Zeile wird in Token getrennt.

Es wird nach den erlaubten Schlüsselwörtern gesucht. Im Falle einer
zusammengesetzten Anweisung (z.B. while, for, if, ...) wird interne
Verwaltungs-Information aufgebaut und rekursiv für die eingebetteten
Anweisungen erneut beim ersten Schritt begonnen.

Unerwartete Schlüsselwörte (z.B. done ohne do, fi ohne if) führen hier
zu einer Fehlermeldung mit Terminierung.

Suche nach angewendeten Aliasen. Im Falle des Einsatzes eines Alias wird
dieser expandiert, und es wird mit dem ersten Schritt weitergearbeitet.

Tilde-Expansion wird durchgeführt. Z.B. wird ~user durch /home/user ersetzt.

Variablen werden expandiert.

Sub-Shell Kommandos der Art $(command) werden durchgeführt.

Arithmetische Ausdrücke $((expression)) werden ausgewertet.

Die Ergebnisse der Expansion der Schritte 5, 6 und 7 werden noch mit
einem Delimiter (Variable IFS) in einzelne Wörter getrennt.

Dateinamen und Regular Expressions werden expandiert. Hier werden z.B.
*, ?, [], *() expandiert.

Das Kommando wird in den möglichen Built-In's, in den definierten
Funktionen und als ausführbares Programm im definierten Pfad gesucht.

Zu Abschluss wird die Ein-/Ausgabe umgeleitet und das Kommando ausgeführt.

===

Re: why bash in $0 ?

<87v8hhcaga.fsf@nosuchdomain.example.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7012&group=comp.unix.shell#7012

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Thu, 27 Apr 2023 13:54:45 -0700
Organization: None to speak of
Lines: 47
Message-ID: <87v8hhcaga.fsf@nosuchdomain.example.com>
References: <u28b4u$6jn$1@reader2.panix.com>
<tnokhj-ep92.ln1@mail.home.palmen-it.de>
<u29qed$5ud$1@reader2.panix.com> <20230426094148.257@kylheku.com>
<on2ohj-j0d1.ln1@mail.home.palmen-it.de>
<u2cv8u$j78$2@reader2.panix.com> <csyCpiemCIwzXzKDM@bongo-ra.co>
<u2e8o7$2m8$2@reader2.panix.com>
<hglqhj-hk9.ln1@mail.home.palmen-it.de>
<u2e9av$2m8$4@reader2.panix.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="c09e77c9fe2c61288802f74759401f85";
logging-data="2182981"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bVZWa+E2Tv2EYVx2U6ubq"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:2XgH460QnmfxHQg5qWsEpMfHAlc=
sha1:0GVk/tac/EVcIbSzMd2IJtUKsck=
 by: Keith Thompson - Thu, 27 Apr 2023 20:54 UTC

Popping Mad <rainbow@colition.gov> writes:
> On 4/27/23 12:46, Felix Palmen wrote:
>> For a script, the script is (logically) the executable, the shell just
>> acts as an interpreter and will set $0 accordingly.
>
> Right, but I would think though, that once #!/bin/bash is reached, that
> a new shell executatible in formed in ram or on the stack with a new PID
> and why should it be aware of what happened previously when the $0 is
> expanded.
>
> Do you see my point of confusion?

Not a new shell executable; the executable is the binary file
"/bin/bash", or whatever. It's a new shell *process*.

It would probably be easier if it consistently expanded to the path
of the shell executable, but the shell process knows the name of
the script it's executing (if any), and that information is much
more useful. In an interactive shell process, there is no script,
so it falls back to the name of the shell. $0 isn't all that useful
in an interactive context. The behavior is specified by POSIX.

Here's the relevant wording from the bash manual:

'0'
($0) Expands to the name of the shell or shell script. This is set
at shell initialization. If Bash is invoked with a file of
commands (*note Shell Scripts::), '$0' is set to the name of that
file. If Bash is started with the '-c' option (*note Invoking
Bash::), then '$0' is set to the first argument after the string to
be executed, if one is present. Otherwise, it is set to the
filename used to invoke Bash, as given by argument zero.

https://www.gnu.org/software/bash/manual/bash.html

or type "info bash" for an interactive view (type 'h' for help if you're
not familiar with the "info" viewer).

It's also described in the POSIX sh manual under "Special Parameters".
(It's difficult to search for because it's shown as "0", not "$0".)

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_02

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: why bash in $0 ?

<83r0s5jaeg.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7013&group=comp.unix.shell#7013

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nn.throttle@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Thu, 27 Apr 2023 23:13:59 +0200
Organization: A noiseless patient Spider
Lines: 74
Sender: Helmut Waitzmann <12f7e638@mail.de>
Message-ID: <83r0s5jaeg.fsf@helmutwaitzmann.news.arcor.de>
References: <u28b4u$6jn$1@reader2.panix.com>
<tnokhj-ep92.ln1@mail.home.palmen-it.de>
<u29qed$5ud$1@reader2.panix.com> <20230426094148.257@kylheku.com>
<on2ohj-j0d1.ln1@mail.home.palmen-it.de>
<u2cv8u$j78$2@reader2.panix.com> <csyCpiemCIwzXzKDM@bongo-ra.co>
<u2e8o7$2m8$2@reader2.panix.com>
<hglqhj-hk9.ln1@mail.home.palmen-it.de>
<u2e9av$2m8$4@reader2.panix.com>
<gcmqhj-j8a.ln1@mail.home.palmen-it.de>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="472d093ae744f2de756f10598d843158";
logging-data="2205647"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UX7u+y5bQeIc9C2wcW1mOpgB2vHnr6bc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:7RtxoH+5u5SQUrkRn7TT164STfs=
sha1:VnIrjyQhUHU1Psy2zGZ4//chPvg=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mail-Copies-To: nobody
 by: Helmut Waitzmann - Thu, 27 Apr 2023 21:13 UTC

felix@palmen-it.de (Felix Palmen):
> * Popping Mad <rainbow@colition.gov>:

> The shebang tells the OS which binary to run as the interpreter
> (feeding the script and all its arguments to it). But keep in
> mind that argv[] contains the WHOLE command line typed, so
> argv[0] is the command's name.

To be more precise:  It's not the command line that is passed to
the invoked binary (in this case: the invoked shell running the
script).  It's the argument vector ("argv", see the "execve(2)"
manual page) of the simple command that is passed to the invoked
binary.

The argument vector, though, is constructed out of the command
line by the invoking shell which reads and parses the command
line as typed by the user.  That's why the "$0" is not seen by
the invoked binary:  The invoking shell, interpreting the "$0",
has already replaced it by its own invocation name.

> The exec() family of functions allows to specify argv[] and the actual
> executable separately, and this is what happens when executing a script
> that has a shebang. The binary named in the shebang is executed, but it
> gets fed the original commandline in argv[], including the original
> argv[0].

At least, my Debian 10 Linux apparently doesn't follow that part
of the last sentence that begins with "but it gets fed":  If I
write the shell script named "show_args", as follows:

#!/bin/sh
bash_printf()
{
bash -c -- 'printf "$@"' bash "$@"
}
ps -o ppid -o sid -o pgid -o pid -o stat \
-o args=argv -p "$$"
bash_printf '%s\n' '"$0" and "$@" (shell-quoted):'
bash_printf '%q\n' "$0" "$@"

… make it readable and executable and invoke it:

./show_args 'Hello,' 'world!'

> As a consequence, you will e.g. also see the script name in 'ps'
> output (and not the shell that's executing it).
>

I get the following output:

PPID SID PGID PID STAT argv
10075 10075 11141 11141 S+ /bin/sh ./show_args Hello, world!
"$0" and "$@" (shell-quoted):
./show_args
Hello\,
world\!

I get essentially the same output, if I invoke it by

sh ./show_args 'Hello,' 'world!'

PPID SID PGID PID STAT argv
10075 10075 11230 11230 S+ sh ./show_args Hello, world!
"$0" and "$@" (shell-quoted):
./show_args
Hello\,
world\!

dali_timer.sh (was: Re: why bash in $0 ?

<l7L2M.570399$5CY7.44166@fx46.iad>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7014&group=comp.unix.shell#7014

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!news.uzoreto.com!peer02.ams4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx46.iad.POSTED!not-for-mail
From: vallor@vallor.earth (vallor)
Subject: dali_timer.sh (was: Re: why bash in $0 ?
Newsgroups: comp.unix.shell
References: <u28b4u$6jn$1@reader2.panix.com>
<tnokhj-ep92.ln1@mail.home.palmen-it.de> <u29qed$5ud$1@reader2.panix.com>
<20230426094148.257@kylheku.com> <on2ohj-j0d1.ln1@mail.home.palmen-it.de>
<u2cv8u$j78$2@reader2.panix.com> <csyCpiemCIwzXzKDM@bongo-ra.co>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; dfc8674 gitlab.gnome.org/GNOME/pan.git)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 136
Message-ID: <l7L2M.570399$5CY7.44166@fx46.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Fri, 28 Apr 2023 08:05:37 UTC
Organization: blocknews - www.blocknews.net
Date: Fri, 28 Apr 2023 08:05:37 GMT
X-Received-Bytes: 4064
 by: vallor - Fri, 28 Apr 2023 08:05 UTC

On Thu, 27 Apr 2023 08:33:19 -0000 (UTC), Spiros Bousbouras wrote:

> On Thu, 27 Apr 2023 00:55:53 -0400 Popping Mad <rainbow@colition.gov>
> wrote:
>> On 4/26/23 13:14, Felix Palmen wrote:
>> > And then, we should finally see how $0 would be utterly pointless if
>> > *not* expanded by the shell ;)
>>
>> If it is always exanded by the shell prior to execution, it is then
>> always the name of the shell being invoked.. Does tht also not seem to
>> be pointless.
>
> It isn't always the name of the shell. Say I have a file named
> my-beautiful-shell-script which contains only 1 line :
> echo $0
>
> .If I do bash my-beautiful-shell-script I see
> my-beautiful-shell-script
>
> If I make my-beautiful-shell-script have 2 lines :
> #!/bin/bash echo $0
>
> and make it executable and execute it with ./my-beautiful-shell-script
> ,
> I see ./my-beautiful-shell-script

I recently had use for $0. But besides that, I have a
few other things going on, and it's a darned useful
script (to me, at least) but I'm also trying to have it
do some crafty stuff with the process group.

I'm relying on "kill -1 0", which if I'm not mistaken, is the
way to kill off the entire pg.

Also, this only works with the older xdaliclock that accepts
command-line options -- the new (gnome) one doesn't seem to support
it.

BTW, hat tip to jwz for an amazing clock. :) I use it with
a green background to snarfle it into an obs scene for streaming
on youtube.

--%< cut here ---
#!/bin/bash
# # wrapper around xdaliclock to use the countdown timer
# # Fri Apr 14 06:40:29 PM PDT 2023 <vallor@vallor.earth>
#

#set -x

export ME=$0

ME=${ME##*/}
ME=${ME%.*}

echo $ME

export COUNT=${1:-600} # 10 minute default

if [ "$COUNT" == "" ]
then
echo Usage: $0 seconds 1>&2
exit 1
fi

export TARGET=$[ $EPOCHSECONDS + $COUNT ]
TARGET="-countdown $TARGET"

case "$ME" in

"dali_game_clock")
export TITLE="-title $ME"
export BG='-bg #00ff00'
export CYCLE='-cycle'
export FONT='-builtin2'
export TZ=UTC
export COUNT=$[ 100 * 86400 ] # for the sleep timeout
export TARGET="-24" # 24-hour clock
;;
"dali_timer")
export TITLE="-title $ME"
export BG='-bg #00ff00'
export CYCLE='-nocycle'
export FONT='-builtin3'
;;

"dali_cycle_timer")
export TITLE="-title $ME"
export BG=''
export CYCLE='-cycle'
export FONT='-builtin3'
;;

"dali_small_timer")
export TITLE="-title $ME"
export BG='-bg #00ff00'
export CYCLE='-nocycle'
export FONT='-builtin2'
;;

*)
export TITLE="-title unknown"
export BG='-bg #00ff00'
export CYCLE='-nocycle'
export FONT='-builtin2'
;;
esac

hang_up_the_phone()
{ HPID=$1;
kill -0 $HPID > /dev/null 2>&1 && kill -1 $HPID;
#kill -0 $HPID && kill -1 $HPID;
}

xdaliclock $TITLE $CYCLE $BG $FONT $TARGET &
export BACK1=$!

{
sleep $COUNT ;
kill -1 0
} &
export BACK2=$!

trap "hang_up_the_phone $BACK1 ; \
hang_up_the_phone $BACK2 ; " 0 CHLD;

wait $BACK1 $BACK2
kill -1 0
exit 0
#/sd
# have I gone overboard in my measures to make
# sure the process group all goes away?

Re: why bash in $0 ?

<918thj-fc.ln1@mail.home.palmen-it.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7015&group=comp.unix.shell#7015

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: felix@palmen-it.de (Felix Palmen)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Fri, 28 Apr 2023 18:15:05 +0200
Organization: palmen-it.de
Lines: 27
Message-ID: <918thj-fc.ln1@mail.home.palmen-it.de>
References: <u28b4u$6jn$1@reader2.panix.com> <tnokhj-ep92.ln1@mail.home.palmen-it.de> <u29qed$5ud$1@reader2.panix.com> <20230426094148.257@kylheku.com> <on2ohj-j0d1.ln1@mail.home.palmen-it.de> <u2cv8u$j78$2@reader2.panix.com> <csyCpiemCIwzXzKDM@bongo-ra.co> <u2e8o7$2m8$2@reader2.panix.com> <hglqhj-hk9.ln1@mail.home.palmen-it.de> <u2e9av$2m8$4@reader2.panix.com> <gcmqhj-j8a.ln1@mail.home.palmen-it.de> <83r0s5jaeg.fsf@helmutwaitzmann.news.arcor.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Apr 2023 18:15:05 +0200
Injection-Info: dont-email.me; posting-host="bdf3532364fb1db65672539bdf0ac6d7";
logging-data="2647187"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lOZT1O7yBSMlY36t/MfGj"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (FreeBSD/13.2-RELEASE (amd64)) tinews.pl/1.1.61
Cancel-Lock: sha256:2hYX6M5XIfPVOkrLdmZob1rhIf2nJ/gk9lcwTTemhrA=
sha1:HuDC+w0p815i9U39/3rAUiFa3XA=
X-PGP-Hash: SHA256
X-PGP-Sig: GnuPG-v2 From,Newsgroups,Subject,Date,Injection-Date,Message-ID
iNUEARYIAH0WIQRpNhPVW79IN7ISOsxUreAGmHnyMQUCZEvxCl8UgAAAAAAuAChp
c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0Njkz
NjEzRDU1QkJGNDgzN0IyMTIzQUNDNTRBREUwMDY5ODc5RjIzMQAKCRBUreAGmHny
MSCzAP4lFRGA11WdPBdQHpVz87OhvGt33yO+OW3BHAnJD6bSJwD+I2f5OLn7XM7I
NZ2UH4KmfafMu5G93IK/9JTRzJa89gk=
=hOFE
X-PGP-Key: 693613D55BBF4837B2123ACC54ADE0069879F231
 by: Felix Palmen - Fri, 28 Apr 2023 16:15 UTC

* Helmut Waitzmann <nn.throttle@xoxy.net>:
> felix@palmen-it.de (Felix Palmen):
>> The exec() family of functions allows to specify argv[] and the actual
>> executable separately, and this is what happens when executing a script
>> that has a shebang. The binary named in the shebang is executed, but it
>> gets fed the original commandline in argv[], including the original
>> argv[0].
>
> At least, my Debian 10 Linux apparently doesn't follow that part
> of the last sentence that begins with "but it gets fed":  If I
> [...]
> I get the following output:
>
> PPID SID PGID PID STAT argv
> 10075 10075 11141 11141 S+ /bin/sh ./show_args Hello, world!

Well, then I was wrong on that one... happens :o so it's always the
shell "shfiting" argv[] by one when running as an interpreter.

Anyways, what I described is perfectly possible, it's used in other
scenarios for sure.

--
Dipl.-Inform. Felix Palmen <felix@palmen-it.de> ,.//..........
{web} http://palmen-it.de {jabber} [see email] ,//palmen-it.de
{pgp public key} http://palmen-it.de/pub.txt // """""""""""
{pgp fingerprint} 6936 13D5 5BBF 4837 B212 3ACC 54AD E006 9879 F231

Re: why bash in $0 ?

<u2jecn$ne2$1@reader2.panix.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7024&group=comp.unix.shell#7024

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix2.panix.com!not-for-mail
From: mrbrklyn@panix.com (Ruben Safir)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Sat, 29 Apr 2023 15:50:47 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <u2jecn$ne2$1@reader2.panix.com>
References: <u28b4u$6jn$1@reader2.panix.com> <tnokhj-ep92.ln1@mail.home.palmen-it.de> <u29qed$5ud$1@reader2.panix.com> <20230426094148.257@kylheku.com> <on2ohj-j0d1.ln1@mail.home.palmen-it.de> <u2cv8u$j78$2@reader2.panix.com> <csyCpiemCIwzXzKDM@bongo-ra.co> <u2e8o7$2m8$2@reader2.panix.com> <hglqhj-hk9.ln1@mail.home.palmen-it.de> <u2e9av$2m8$4@reader2.panix.com> <87v8hhcaga.fsf@nosuchdomain.example.com>
Injection-Date: Sat, 29 Apr 2023 15:50:47 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="panix2.panix.com:166.84.1.2";
logging-data="24002"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.3 (amd64))
 by: Ruben Safir - Sat, 29 Apr 2023 15:50 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Popping Mad <rainbow@colition.gov> writes:
>> On 4/27/23 12:46, Felix Palmen wrote:
>>> For a script, the script is (logically) the executable, the shell just
>>> acts as an interpreter and will set $0 accordingly.
>>
>> Right, but I would think though, that once #!/bin/bash is reached, that
>> a new shell executatible in formed in ram or on the stack with a new PID
>> and why should it be aware of what happened previously when the $0 is
>> expanded.
>>
>> Do you see my point of confusion?
>
> Not a new shell executable; the executable is the binary file
> "/bin/bash", or whatever. It's a new shell *process*.
>
> It would probably be easier if it consistently expanded to the path
> of the shell executable, but the shell process knows the name of
> the script it's executing (if any), and that information is much
> more useful. In an interactive shell process, there is no script,
> so it falls back to the name of the shell. $0 isn't all that useful
> in an interactive context. The behavior is specified by POSIX.
>
> Here's the relevant wording from the bash manual:
>
> '0'
> ($0) Expands to the name of the shell or shell script. This is set
> at shell initialization. If Bash is invoked with a file of
> commands (*note Shell Scripts::), '$0' is set to the name of that
> file. If Bash is started with the '-c' option (*note Invoking
> Bash::), then '$0' is set to the first argument after the string to
> be executed, if one is present. Otherwise, it is set to the
> filename used to invoke Bash, as given by argument zero.
>
> https://www.gnu.org/software/bash/manual/bash.html
>

excellent - thank you

> or type "info bash" for an interactive view (type 'h' for help if you're
> not familiar with the "info" viewer).
>
> It's also described in the POSIX sh manual under "Special Parameters".
> (It's difficult to search for because it's shown as "0", not "$0".)
>
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_02
>

Re: why bash in $0 ?

<20230430195339.559@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7033&group=comp.unix.shell#7033

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Mon, 1 May 2023 02:55:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <20230430195339.559@kylheku.com>
References: <u28b4u$6jn$1@reader2.panix.com>
<tnokhj-ep92.ln1@mail.home.palmen-it.de> <u29qed$5ud$1@reader2.panix.com>
<20230426094148.257@kylheku.com> <u2cv2v$j78$1@reader2.panix.com>
Injection-Date: Mon, 1 May 2023 02:55:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3146195d12c14813980c0817d8ee3f9c";
logging-data="1942"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fFmWTMyOPbvtznsETdNOxkHyl07LGcQA="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:jtiFMUTuP5XkL+14yescbdYVvcg=
 by: Kaz Kylheku - Mon, 1 May 2023 02:55 UTC

On 2023-04-27, Popping Mad <rainbow@colition.gov> wrote:
> On 4/26/23 12:44, Kaz Kylheku wrote:
>> Why would we expect "ps", rather than "grep"?
>
>
> actually, I would think it would be basename, not ps.

Yes; you and Felix are right. I have a blind spot to the insanity
of a basic string-processing function like basename not being
a built-in!

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: why bash in $0 ?

<837ctsi8hn.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7036&group=comp.unix.shell#7036

  copy link   Newsgroups: comp.unix.shell
Path: rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nn.throttle@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: why bash in $0 ?
Date: Mon, 01 May 2023 13:41:56 +0200
Organization: A noiseless patient Spider
Lines: 65
Sender: Helmut Waitzmann <12f7e638@mail.de>
Message-ID: <837ctsi8hn.fsf@helmutwaitzmann.news.arcor.de>
References: <u28b4u$6jn$1@reader2.panix.com>
<tnokhj-ep92.ln1@mail.home.palmen-it.de>
<u29qed$5ud$1@reader2.panix.com> <20230426094148.257@kylheku.com>
<on2ohj-j0d1.ln1@mail.home.palmen-it.de>
<u2cv8u$j78$2@reader2.panix.com> <csyCpiemCIwzXzKDM@bongo-ra.co>
<u2e8o7$2m8$2@reader2.panix.com>
<hglqhj-hk9.ln1@mail.home.palmen-it.de>
<u2e9av$2m8$4@reader2.panix.com>
<gcmqhj-j8a.ln1@mail.home.palmen-it.de>
<83r0s5jaeg.fsf@helmutwaitzmann.news.arcor.de>
<918thj-fc.ln1@mail.home.palmen-it.de>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>, Helmut Waitzmann <12f7e638@mail.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="10a4a1d0867aaaf89b5200ba3a886284";
logging-data="183233"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HJUCrpd+fjHgaoMYFyE4Q7MQ9kMmlq78="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:iS/t8wQp+LP8nXccUMmCt1BK+G8=
sha1:BgTca8dG2ffwgid9CN8qaK4gZW4=
Mail-Copies-To: nobody
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>, Helmut Waitzmann <12f7e638@mail.de>
 by: Helmut Waitzmann - Mon, 1 May 2023 11:41 UTC

felix@palmen-it.de (Felix Palmen):
> * Helmut Waitzmann <nn.throttle@xoxy.net>:
>> felix@palmen-it.de (Felix Palmen):
>>> The exec() family of functions allows to specify argv[] and
>>> the actual executable separately, and this is what happens
>>> when executing a script that has a shebang. The binary named
>>> in the shebang is executed, but it gets fed the original
>>> commandline in argv[], including the original argv[0].
>>
>> At least, my Debian 10 Linux apparently doesn't follow that
>> part of the last sentence that begins with "but it gets fed": 
>> If I
>> [...]
>> I get the following output:
>>
>>
>> PPID SID PGID PID STAT argv
>> 10075 10075 11141 11141 S+ /bin/sh ./show_args Hello, world!
>
> Well, then I was wrong on that one... happens :o so it's always
> the shell "shfiting" argv[] by one when running as an
> interpreter.

The shell examines its argument list, detects, which argument
names the shell script to be read and interpreted, and puts the
value of that argument into the positional parameter "$0".  That
argument doesn't necessarily have to be the argv[1] invocation
argument.  For example, when running a shell script like

sh -x -v - ./show_args 'Hello,' 'world!'

(i. e. with command echoing and tracing enabled and the end of
options explicitly marked) argv[4] will be the name of the script
file "./show_args", and that is what will be available as "$0"
inside of the script.

This mechanism of copying the shell script's name into "$0" is
done by the invoked shell, even if the shell script does not
start with a "#!" line.

As far as I understand it, a member of the "exec" family of
functions, when given a shell script file name as the first
("path" or "file", see the manual page "exec(3)") parameter, for
example

execlp("the_shell_script", "two", "parameters", 0)

(if the variant of the "exec" family function is a "exec…p"
variant and the "the_shell_script" parameter doesn't contain a
slash ("/"), searches for the "the_shell_script" file according
to the "PATH" environment variable, replaces the name by the full
path name of the script file found, for example
"/path/to/the_shell_script"), opens that file for reading, reads
the pathname of the shell to be invoked and an optional parameter
from the

#! /name/of/the/shell optional_parameter

line, and invokes the shell given in that "#!" line (together
with the optional parameter if given) followed by the shell
script pathname and the remaining parameters, like

execl("/name/of/the/shell", "optional_parameter",
"/path/to/the_shell_script", "two", "parameters", 0)

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor