Command Prompt prompt in Linux/Unix

Source: Internet
Author: User
The guy who is familiar with DOS is trying to make UNIX like DOS,
One of them is to set the Unix prompt as $ p $ G. The following describes the method.

The GNU bash (Bourne again shell) is more convenient for different shell settings)
And KSh (Korn shell) and tcsh (enhanced version of CSH, CSH in Linux is
Symbol connection ). The General Sh (Bourne shell) and CSH settings are cool. One by one
Various shell setting methods:

Ksh:
Because KSh treats the prompt variable PS1 as a special variable, KSh automatically changes
The new PS1 value, so you just need to simply add the environment variable $ PWD corresponding to the current path to PS1:

PS1 = '$ PWD $'

SH:
Because the Bourne shell only uses PS1 as a common variable and does not support aliases, no
To perfectly implement the same functions in DOS, the solution is to redefine a command (such as XCD)
Implement it as a function:

XCD () {CD $ *; PS1 = "'pwd' $ ";}

Switch the directory with XCD each time.

CSH:
CSH does not perform special processing on the prompt variable $ prompt, But it supports aliases. You can modify them.
CD syntax to make it automatically modify the prompt:

Alias setprompt 'set prompt = "$ {CWD} % "'
Setprompt # To set the initial prompt
Alias CD 'chdir \! * & Setprompt'

Bash:
Bash provides some special variables to support prompt settings. \ W indicates the current path and sets
Equivalent to replacing $ home ~, To shorten the length of the prompt.

PS1 = '\ W $'

In Linux, the hostname is also added:

PS1 = '\ H: \ W $' # \ h indicates the hostname

In order to be more like DOS, we can clearly distinguish different commands. I usually add a line break:

PS1 ='
\ H: \ W $'

Tcsh:
The tcsh method is similar to bash, except that the variable names are different:

Set prompt = '% ~ '# % ~ Indicates the current path

Sample:
Different practices in Solaris: how to display a directory in the command line?
The guy who is familiar with DOS is trying to make UNIX like DOS,
One of them is to set the Unix prompt as $ p $ G. The following describes the method.
The GNU bash (Bourne again shell) is more convenient for different shell settings)
And KSh (Korn shell) and tcsh (enhanced version of CSH, CSH in Linux is
Symbol connection ). The General Sh (Bourne shell) and CSH settings are cool. One by one
Various shell setting methods:
Ksh:
Because KSh treats the prompt variable PS1 as a special variable, KSh automatically changes
The new PS1 value, so you just need to simply add the environment variable $ PWD corresponding to the current path to PS1:
PS1 = '$ PWD $'
SH:
Because the Bourne shell only uses PS1 as a common variable and does not support aliases, no
To perfectly implement the same functions in DOS, the solution is to redefine a command (such as XCD)
Implement it as a function:
XCD () {CD $ *; PS1 = "'pwd' $ ";}
Switch the directory with XCD each time.
CSH:
CSH does not perform special processing on the prompt variable $ prompt, But it supports aliases. You can modify them.
CD syntax to make it automatically modify the prompt:
Alias setprompt 'set prompt = "$ {CWD} % "'
Setprompt # To set the initial prompt
Alias CD 'chdir \! * & Setprompt'
Bash:
Bash provides some special variables to support prompt settings. \ W indicates the current path and sets
Equivalent to replacing $ home ~, To shorten the length of the prompt.
PS1 = '\ W $'
In Linux, the hostname is also added:
PS1 = '\ H: \ W $' # \ h indicates the hostname
In order to be more like DOS, we can clearly distinguish different commands. I usually add a line break:
PS1 ='
\ H: \ W $'
Tcsh:
The tcsh method is similar to bash, except that the variable names are different:
Set prompt = '% ~ '# % ~ Indicates the current path

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.