PS1 값을 변경하는 방법.

PS1 값을 변경하는 방법.

저는 Linux 2.6.18 시스템의 루트로 로그인했습니다. PS1의 값을 다음과 같이 변경했습니다.

export PS1="$PWD> "

작동하고 명령 프롬프트를 홈 디렉토리로 하드코딩하고 그 뒤에 >. 이제 내가 지금 있는 현재 디렉터리를 표시하고 싶습니다.

어떻게 설정하나요? PS1 변수의 작동 방식을 설명하는 코드를 설명하는 문서가 있습니까?

답변1

이 시도

PS1="[\w]$ " 내보내기

여기

w는 현재 작업 디렉토리를 나타냅니다.

더 많은 정보는 이것을 참조하세요링크


편집: PS1과 PS2에서 bash가 이해하는 특수 문자는 다음과 같습니다.

\a : an ASCII bell character (07)
\d : the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format} : 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

답변2

비지박스가 아닌 bash를 실제로 실행하는지 확인할 수 있나요?

echo $SHELL

쉘을 보여줘야합니다. (나는 /bin/bash라고 가정한다)

그럼 당신은 볼 수 있습니다

ls -l /bin/bash

다른 곳(링크)을 가리키는 경우 또는 실제 실행 파일인 경우

답변3

이것은 다른 Linux 시스템에서도 작동합니다. 여기서는 왜 작동하지 않는지 모르겠습니다.

아마도 다른 컴퓨터에는 다음과 같은 것이 있기 때문일 것입니다.

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

관련 정보