My current prompt format string is generated by an outside script that is provided by the organization. I want to manipulate it a bit (add time to the string) for that I need my current format string.

I can understand it by going through the .cshrc (and its linked scripts) - but it would be much easier if I can ask the cshell for my current prompt format string.

Do you know of a way to get the format string of the current shell?


  • The prompts are stored in variables $PS1, $PS2, AND $PS3. – ctrl-alt-delor Mar 25 '19 at 8:04
  • In csh the prompt is stored in the variable named prompt (set prompt = 'foo% ') not PS1. – mosvy Mar 25 '19 at 12:23
  • In tcsh the prompt also supports various escape sequences, similarly to bash or zsh. Refer to the tcsh(1) manpage. – mosvy Mar 25 '19 at 12:43

The (t)csh prompt variable is $prompt[1], so the direct answer to your question is:

printf '%s\n' "$prompt"

In tcsh (but not in the original csh) you can use a %t escape for the time in 12h am/pm format:

% set prompt = "%t - $prompt"
1:53pm - % _

or %P for the 24h format with seconds:

% set prompt = "$prompt (%P) "
%  (13:55:31) _

You can see the full list of prompt escapes in the tcsh(1) manpage.

[1] tcsh also has $prompt2 for the foreach/while loops and \ line continuations, and $prompt3 for its spelling correction feature.

  • 1
    those escapes only work in tcsh, not in csh. Also , there's no point in that ugly quote mixing, set prompt = "%t - $prompt" will do just as well. – mosvy Mar 26 '19 at 9:44
  • Than you, mosvy! I've updated the post to incorporate your suggestion. I don't have a plain csh handy to test, so please let me know if it needs further updates (or feel free to edit the post directly!). – Jeff Schaller Mar 26 '19 at 10:35

Since you are using a computer from the company that you work for, ask your IT department for assistance. Perhaps it is against the company policy to modify the prompt. If not, perhaps they can create a custom prompt for you or update their company-wide prompt. Otherwise they most likely will be able to assist you in creating your own custom prompts.

As mentioned in the comments, "the prompts are stored in variables $PS1, $PS2, AND $PS3," although this might depend on the flavor of your operating system, which you forgot to mention.

  • Of course I can ask IT/CAD department - but that will waste time for all persons involved (vs the option to ask the shell for this information). The flavor of the OS is CentOS 6.6 – Roee Mar 25 '19 at 11:53
  • I fail to see how that would waste time for all persons involved. Does that mean you rather waste our time than the time of the IT department who is being paid to assist in all things IT-related going on in your company? – Tommiie Mar 25 '19 at 12:01
  • LOL what else is forbidden by the IT department's policy? looking askew at the monitor or typing with your thumbs? In csh the prompt is stored in the variable named ... prompt (set prompt = 'foo% ') not PS1. Your answer is completely bogus. – mosvy Mar 25 '19 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.