So ändern Sie den PS1-Wert.

3947
VSN

Ich bin als Root einer Linux 2.6.18-Maschine angemeldet. Ich habe den Wert von PS1 geändert als:

export PS1="$PWD> " 

Es funktioniert und kodiert die Eingabeaufforderung als Ausgangsverzeichnis, gefolgt von einem >. Jetzt möchte ich das aktuelle Verzeichnis anzeigen, in dem ich mich gerade befinde.

Wie kann ich das einstellen? Gibt es ein Dokument, in dem die Codes erläutert werden, die erklären, wie die PS1-Variable funktioniert?

0

3 Antworten auf die Frage

3
max

Versuche dies

export PS1 = "[\ w] $"

Hier

w steht für das aktuelle Arbeitsverzeichnis

Weitere Informationen finden Sie unter diesem Link


Edit: Dies sind die Sonderzeichen, die Bash in PS1 und PS2 versteht

\a : an ASCII bell character (07) \d : the date in "Weekday Month Date" format (e.g., "Tue May 26") \D : the format is passed to strftime(3) and the result is inserted into  the prompt string; an empty format results in a locale-specific time  representation. The braces are required \e : an ASCII escape character (033) \h : the hostname up to the first '.' \H : the hostname \j : the number of jobs currently managed by the shell \l : the basename of the shell’s terminal device name \n : newline \r : carriage return \s : the name of the shell, the basename of $0 (the portion following the final  slash) \t : the current time in 24-hour HH:MM:SS format \T : the current time in 12-hour HH:MM:SS format \@ : the current time in 12-hour am/pm format \A : the current time in 24-hour HH:MM format \u : the username of the current user \v : the version of bash (e.g., 2.00) \V : the release of bash, version + patch level (e.g., 2.00.0) \w : the current working directory, with $HOME abbreviated with a tilde \W : the basename of the current working directory, with $HOME abbreviated with  a tilde \! : the history number of this command \# : the command number of this command \$ : if the effective UID is 0, a #, otherwise a $ \nnn : the character corresponding to the octal number nnn \\ : a backslash \[ : begin a sequence of non-printing characters, which could be used to embed a  terminal control sequence into the prompt \] : end a sequence of non-printing characters 
Das hat funktioniert! Vielen Dank! Aber warum hat $ PWD hier nicht funktioniert, aber anderswo? VSN vor 11 Jahren 0
@VSN: Weil $ PWD zum Zeitpunkt der Einstellung von PS1 erweitert wurde. Beachten Sie Folgendes: "export MYPROMPT = aaa; export PS1 =" $ MYPROMPT ". Dies würde Ihre Eingabeaufforderung auf" aaa "setzen. Wenn Sie dann" MYPROMPT = bbb "exportieren, ändert sich Ihre Eingabeaufforderung nicht, da PS1 nur den Inhalt von MYPROMPT speichert. kein Verweis auf die Variable MYPROMPT. Terje Mikal vor 11 Jahren 0
@Terje Mikal: Ich verstehe. Aber wie funktioniert PS1 = "$ PWD>" auf anderen Linux-Maschinen? Nach dieser Philosophie sollte es nirgendwo funktionieren. Fällt Ihnen ein Grund ein? VSN vor 11 Jahren 0
@ RedGrittyBrick: Das sind sehr nützliche Informationen. Danke vielmals! Fällt Ihnen ein Grund ein, warum es hier nicht funktioniert, aber anderswo? VSN vor 11 Jahren 0
@VSN Auf meinen Linux-Systemen aktualisiert PS1 = "$ PWD>" die Aufforderung nach einer `cd` nicht. Auf Ihren anderen Systemen ist `cd` vielleicht ein Alias, der PS1 aktualisiert. RedGrittyBrick vor 11 Jahren 0
0

Kannst du sicherstellen, dass du wirklich bash ausführst, und nicht irgendeine Art von busybox?

echo $SHELL 

sollte dir die Schale zeigen. (Ich nehme an / bin / bash)

dann kannst du mit schauen

ls -l /bin/bash 

wenn es woanders hinweist (ein Link) oder wenn es sich um die eigentliche ausführbare Datei handelt

Ich habe nachgesehen. Ich lief / bin / bash / VSN vor 11 Jahren 0
0
RedGrittyBrick

Dies funktioniert auf anderen Linux-Maschinen. Ich weiß nicht, warum es hier nicht funktioniert.

Vielleicht weil du auf den anderen Maschinen sowas hast

$ PS1="\$(pwd)> " /tmp> cd / />