Prompt path display issue


 
Thread Tools Search this Thread
# 1  
Prompt path display issue

I use the following command to print the current directory above the command prompt

Code:
set prompt="`exec pwd`\n$USER@`hostname -s` %B: % > "

The output is something like this

Code:
<current path>
$USER@hostname >

But when I try to CD to any other directory and press the return key, the displayed PWD is never changed.

Last edited by rbatte1; 10-20-2014 at 10:52 AM.. Reason: Changed ICODE tags to just CODE tags
# 2  
Quote:
Originally Posted by aelhosiny
I use the following command to print the current directory above the command prompt

Code:
set prompt="`exec pwd`\n$USER@`hostname -s` %B: % > "

The output is something like this

Code:
<current path>
$USER@hostname >

But when I try to CD to any other directory and press the return key, the displayed PWD is never changed.
Hello aelhosiny,

Not sure completely about your requirement, but if you want to change prompt string then you can use PS1 command as follows.

Code:
[singh@localhost awk_programming]$ 
[singh@localhost awk_programming]$ PS1="TEST $"
TEST $man test

Similarly you can put any pwd according to your need in it. Also if you want to permanently fix prompt string you can add this command in the .profile of user.

Thanks,
R. Singh

Last edited by rbatte1; 10-20-2014 at 10:53 AM.. Reason: Changed ICODE tags to just CODE tags because I did so in above quoted post
# 3  
Sorry,
I did not mention that I'm using csh as default shell on centos 5.10
It's the default shell set by the sys admin

Accordingly the PS1 does not exist Smilie
I have already added these commands to my .cshrc

---------- Post updated at 01:52 PM ---------- Previous update was at 01:42 PM ----------

Quote:
Originally Posted by RavinderSingh13
Hello aelhosiny,

Not sure completely about your requirement, but if you want to change prompt string then you can use PS1 command as follows.

Code:
[singh@localhost awk_programming]$ 
[singh@localhost awk_programming]$ PS1="TEST $"
TEST $man test

Similarly you can put any pwd according to your need in it. Also if you want to permanently fix prompt string you can add this command in the .profile of user.

Thanks,
R. Singh

What I need the command prompt to display the full path and $USER@HOST each in a separate line instead of both displayed in the same line so that I will have:

Code:
<The exact long path>
<my username> @ <hotsname> $

As you see, the path is not in the same line with the username and host.

Last edited by rbatte1; 10-20-2014 at 10:53 AM.. Reason: Changed ICODE tags to just CODE tags
# 4  
Hello aelhosiny,

As I doesn't have csh so I can't test commands, could you please check if following link can help you in same.

how to set PS1 in csh - HP Enterprise Business Community

Thanks,
R. Singh
# 5  
After some search I found two alternatives
The first -my favorite- is :

Code:
set prompt="%{\033[0;33m%}%~%{\033[1;30m%} \n%{\033[0;32m%}%n@%m:>%{\033\[1;31m%} "

The second is
Code:
alias set_prmpt 'set prompt="`exec  \ pwd`\n%B$USER@`hostname -s` : > "' 
set_prmpt
alias cd 'chdir \!* && set_prmpt'


Last edited by rbatte1; 10-20-2014 at 10:54 AM.. Reason: Changed ICODE tags to just CODE tags
# 6  
# 7  
dynamic path prompt for csh and tcsh

I found this in a .cshrc startup.
Code:
if ( ! $?HOST ) then
 # define env-var HOST for old csh
 setenv HOST `/bin/uname -n`
endif
# Silent "cd" and no prompt when batch job is running
# (no tty)
if { /usr/bin/tty -s } then
 # always user@host:
 set promptn="$USER@${HOST}:"
 if ( $?tcsh ) then
  # prompt for tcsh only:
  set prompt="${promptn}%c3: "
 else
  # prompt for old csh:
  alias setprompt 'set wdh=$cwd:h;set prompt="${promptn}$wdh:t/${cwd:t}: "'
  alias cd      'cd \!*; setprompt'
  alias pushd   'pushd \!*; setprompt'
  alias popd    'popd \!*; setprompt'
  alias chdir   'chdir \!*; setprompt'
  setprompt
 endif
endif


Last edited by MadeInGermany; 10-24-2014 at 05:49 PM..
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #944
Difficulty: Medium
The original smurf.c was written by Dan Moschuk, aka TBone.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash function to suppress warning message for specific text and display prompt

In the below bash function multiple variants are input and stored in a variable $variant, and each is written to an out file at c:/Users/cmccabe/Desktop/Python27/out.txt stored on a separate line. # enter variant phox2b() { printf "\n\n" printf "What is the id of the patient getting... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. UNIX for Dummies Questions & Answers

Display the absolute path...

I don't understand the question below..any can help me? thanks Display the absolute path of the executable used when a 'grep' command is entered on the command line: ---------- Post updated at 08:30 PM ---------- Previous update was at 08:29 PM ---------- absolute (2 Replies)
Discussion started by: wk9031
2 Replies

3. Shell Programming and Scripting

How to display current time in the prompt

Hello All, I would like to display the current time in prompt. I tried using following command: export PS1="$(date +%k:%M:%S) $ " but it gave me a fixed time in prompt whereas my objective is to get the current time everytime. $ export PS1="$(date +%k:%M:%S) $ " 17:42:42 $ 17:42:42 $... (32 Replies)
Discussion started by: manishdivs
32 Replies

4. Shell Programming and Scripting

how to change unix cmd display prompt?

I am new to to unix and I want to make my own basic shell. What is the code I can use to change the unix cmd console display? For example my unix display prompt says MyCompterName~, I want it to say WhatEverMan~ (3 Replies)
Discussion started by: megaearth77
3 Replies

5. UNIX for Advanced & Expert Users

Help-prompt for path and take this as input in find command

HI , I am trying to wite a script that will prompt me saying " what is path that you want to find ?". once i specify the path, the script should put this path in the find command mentioned below and execute the script: find <path> -ctime +200 -type f -exec ls -l {} \; for example : ... (7 Replies)
Discussion started by: bsandeep_80
7 Replies

6. Shell Programming and Scripting

How to change prompt color when changing path

Hi all, Can you tell me how to change the prompt color (only the path part) when I chnange directory with "cd"? I use the sequence below in ".bashrc" (Solaris 8) to change my prompt colors and I'd like to modify it to change the path color when I cange directory. PSC() { echo -ne "\"; }... (0 Replies)
Discussion started by: majormark
0 Replies

7. Solaris

How to display hostname in command prompt

Anyone know How to configure solaris 8 to display hostname in command prompt , everytime when you open a terminal screen . (3 Replies)
Discussion started by: civic2005
3 Replies

8. Solaris

Solaris 10 install doesn't display Network Connectivity prompt page

I have two Dell x86 machines on which I am attempting to install Solaris 10 from CD. I am not doing a Jumpstart install. This is my first experience in installing Solaris (or any other OS). I am following the instructions at How to Quickly Install the Solaris 10 1/06 OS The first machine... (3 Replies)
Discussion started by: sarahsi
3 Replies

9. UNIX for Dummies Questions & Answers

Path in prompt line?

Can anyone tell me what makes the current path appear in the prompt ? thx (4 Replies)
Discussion started by: Leitwolf
4 Replies

10. Solaris

no boot prompt display

just put blank harddisk in my ultra10. i see no display to show me the boot> prompt. i don't know what happened....?? Got a third party graphic card. Display was ok. Monitor seems to be ok. i used different one with same result. (1 Reply)
Discussion started by: S26+
1 Replies

Featured Tech Videos