Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pfad des Scripts

1 view
Skip to first unread message

Alexander Goetzenstein

unread,
Oct 8, 2022, 4:56:45 AM10/8/22
to
Hallo,
mit basename $0 erhält man den Namen des Scripts, das diesen Befehl
ausführt, allerdings ohne den Pfad. Wie kann man den Pfad des Scripts
(nicht des aktuellen Verzeichnisses) erhalten, mit oder ohne den
Scriptnamen?


--
Gruß
Alex

Marcel Logen

unread,
Oct 8, 2022, 5:07:17 AM10/8/22
to
Alexander Goetzenstein in de.comp.os.unix.shell:
Da könnte dirname(1) evtl. helfen.

Es kommt aber IMHO darauf an, wie das Script aufgerufen wird.

| user15@o15:~/ybtra-o15/mist/mist3$ cat script.bash
| #!/usr/bin/bash
| echo Hallo
| basename "$0"
| dirname "$0"
| echo ENDE

| user15@o15:~/ybtra-o15/mist/mist3$ ./script.bash
| Hallo
| script.bash
| .
| ENDE

| user15@o15:~/ybtra-o15/mist/mist3$ /home/user15/ybtra-o15/mist/mist3/script.bash
| Hallo
| script.bash
| /home/user15/ybtra-o15/mist/mist3
| ENDE

Ansonsten könnte man vielleicht noch mit "pwd" arbeiten.

Marcel
--
╭───────╮ ╭────╮ ╭───╮ ╭───╮ ..67..
╰────╮ │ ╰─╮ │ ..43..╭───╯ ╰──╯ ╰────╮ ╭
─╮ ╭─╮ ╭──╮ ╭─╯ ╰──╮ ╭─╮ │ ╰─╮ ╭─╮ ╭─╮ ╰──╮ ╭────────────╯ │
╰─╯ ╰────╯ ╰──╯ ..19..╰─╯ ╰─╯ ╰──╯ ╰──╯ ╰─────╯ ╰───────────────╯

Alexander Goetzenstein

unread,
Oct 8, 2022, 5:19:18 AM10/8/22
to
Hallo,

Am 08.10.22 um 11:07 schrieb Marcel Logen:
> Da könnte dirname(1) evtl. helfen.

Danke, das ist es.



--
Gruß
Alex

fb

unread,
Oct 8, 2022, 5:25:31 AM10/8/22
to
Am 08.10.22 um 10:56 schrieb Alexander Goetzenstein:
Der steht in "$0"

Stefan Wiens

unread,
Oct 8, 2022, 5:56:36 AM10/8/22
to
Wozu benötigt man diese Information?
Wenn das Script der Shell per Pipe verabreicht wurde, kommt
man sowieso nicht mehr daran, und sonst ist es anfällig für
Race Conditions.

--
Stefan

Alexander Goetzenstein

unread,
Oct 8, 2022, 7:04:41 AM10/8/22
to
Hallo,

Am 08.10.22 um 11:56 schrieb Stefan Wiens:
> Wozu benötigt man diese Information?

damit will ich das Log aufhübschen.


--
Gruß
Alex
0 new messages