$PWD sur unix

Fermé
royinfo - 7 janv. 2009 à 17:09
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 - 8 janv. 2009 à 16:03
Bonjour,

Je suis un p'tit nouveau sur Unix et j'aimerais redefinir dans mon profile la variable PS1 afin de voir en tout temps le path dans lequel je suis.

Je connecte en temps que ROOT.

j'utilise la commande : PS1="$LOGNAME->$PWD" ;export PS1

lors du Login, le prompt est : root-> il n'affiche pas le repertoire.

si je fais echo de $PWD il est blanc.. pourquoi ?

merci

7 réponses

jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 4 895
7 janv. 2009 à 17:18
Salut,
PS1="[\u ->\w] # "
Si tu veux que ce soit permanent tu mets ça dans le .bashrc du "root" :
PS1="[\u ->\w] # "
export PS1
0
Bonjour, je viens tout juste d'executer la commande mentionnee PS1="[\u ->\w] # " et le resultat est :


[\u ->\w] #
0
jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 4 895
7 janv. 2009 à 17:35
[tmpfs]$ echo $PS1
[\W]$

[tmpfs]$ PS1="[\u -> \w]$ "

[jp -> ~/tmpfs]$ cd /usr/share/

[jp -> /usr/share]$ cd -
/home/jp/tmpfs

[jp -> ~/tmpfs]$ echo $PS1
[\u -> \w]$

[jp -> ~/tmpfs]$ PS1="[\W]$ "

[tmpfs]$ echo $PS1
[\W]$

[tmpfs]$
Quel système UNIX utilises-tu ? Quel shell ?
0
Bonjour a vous et merci de me repondre.

Il s'agit d'un IBM pc server 325 qui doit dater des annees 1980.

Shell ... aucune idee.

lorsque je me connecte avec root je retrouve les fichiers suivants :

Je pensais simplement ajouter ma petite commande dans le fichier .profile

total 6076
-rw------- 1 root sys 52 Apr 23 1998 .Xauthority
-rw-r--r-- 1 root bin 27 Mar 18 1992 .exrc
-r-------- 1 root auth 0 Jan 7 11:47 .lastlogin
-rw------- 1 root root 15 Apr 22 1998 .mailrc
-rw-r--r-- 1 root sys 5 May 8 2007 .mosaicpid
drwxrwxrwx 3 root sys 80 Oct 13 1999 .netscape
drwxr-xr-x 3 bin bin 64 Apr 23 1998 .odtpref
-rw------- 1 root root 984 Jan 7 10:16 .profile
-rw------- 1 root sys 786 Dec 17 14:01 .profile.tmp
-rw-r--r-- 1 root sys 2688 Dec 17 15:29 .roy_demo
-rw-r--r-- 1 root sys 123 Jul 9 2007 .scoadmin.pref
-rw-r--r-- 1 root root 899 Apr 22 1998 .utillist2
drwxr-xr-x 5 root sys 128 Apr 23 1998 .xdt_dir
-rw-r--r-- 1 root sys 0 Apr 23 1998 .xdtsupCheck
0
fsaelens > royinfo
7 janv. 2009 à 18:07
pour connaître ton shell, tape ps, il devrait apparaître en première ligne (j'espère).
0
royinfo > fsaelens
7 janv. 2009 à 18:17
Je tape ps et voici le resultat.

root->/ps
PID TTY TIME CMD
5065 ttyp1 00:00:00 ps
4634 ttyp1 00:00:00 login
4640 ttyp1 00:00:00 sh
root->/
0
fsaelens > royinfo
7 janv. 2009 à 18:32
donc ton shell est: sh

ps: c'est marrant, chez moi c'est le process le plus ancien d'abord mais chez toi c'est l'inverse.
0
jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 4 895
7 janv. 2009 à 18:29
echo $SHELL
Pour connaitre ton shell de connexion ou
grep $USER /etc/passwd
Sinon, affiche le contenu du ".profile".
0
Il utilise SCO open server..

voici le contenu du .profile de ROOT. Comme vous pouvez voir j'ai redefini PS1 et il ne me donne pas mon path, seulement le LOGNAME. c'est comme si $PWD n'est pas defini nulle part.. si echo de $PWD il me retourne un blanc.



SHELL=/bin/sh
HOME=/

PATH=/bin:/etc:/usr/bin:/tcb/bin

PATH=$PATH:/u/PCA:/u/PCA/bin:/u/PCA/IQ

IQCAP=/u/PCA/IQ/iqcap
IQDATA=/FILES
IQDD=/u/PCA/IQ


# set terminal type
eval `tset -m ansi:${TERM:-ansi} -m :\?${TERM:-ansi} -e -r -s -Q`
export TERM PATH SHELL HOME IQCAP IQDATA IQDD

PS1="$LOGNAME->$PWD" ;export PS1

stty intr "^c"
[ -x /bin/mesg ] && mesg n # if mesg is installed...
root->
0
jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 4 895
7 janv. 2009 à 19:19
0
J'ai essaye tous les exemples ci-dessous et rien ne fonctionne..

J'ai modifie le .profile.. ne fonctionne pas .. j'ai cree un .cshrc tel que mentionne et ne fonctionne pas .. j'ai cree un .kshrc tel que mentionne et ne fonctionne pas

Est-ce que quelqu'un a une idee.

merci.

Changing your prompt
A prompt will appear after you have logged into your system. The UNIX system stores this prompt in a variable.

To change your prompt, you reset the value of the prompt variable.

In the Bourne and Korn shells, the prompt variable is called PS1 (prompt string 1). In the C shell, the prompt variable is called prompt.

All three shells have a secondary prompt as well as the main prompt. This secondary prompt is shown when you type a command that makes the shell expect further input.

For example, in the Bourne shell, the secondary prompt is ``>'' by default:

$ for i in *.tut
>

Here, you are saying to the shell ``for every file (i represents every file) ending in .tut ...'' The shell gives you a secondary prompt because it needs more information to complete your command.
In the Bourne and Korn shells, the secondary prompt is stored in the variable PS2 (prompt string 2), which you can reset. You cannot reset the secondary prompt in the C shell. To reset PS2 in sh or ksh, follow the instructions below, substituting PS2 for PS1.

To reset your prompt in the Bourne or Korn shells, type PS1=value where value is the value you want to assign to the prompt variable.

For example, to set your prompt to say ``Yo'', you would add the following line to your .profile or .kshrc:

PS1=Yo

C-shell users would add the following line to their .login:
set prompt=Yo

Q: When I change my prompt, I lose the space between my prompt and where the command line starts. How do I get this back?

A: To keep the space between the prompt and the command line, you need to put a space after your new prompt. To get the shell to notice the space, you need to enclose the whole prompt string in double quotes.

In ksh or sh, add the following line to your .profile:

PS1="Hello friend "

In csh, add the following line to your .login:
set prompt="Hello friend "

Q: How do I get my prompt to show the current directory, like on DOS?

A: In sh, add the following line to your .profile:

nd() { cd $* ; PS1="`pwd` "; }

Now, use the command nd, which you just created, to change to a new directory and display the directory as the prompt.
In ksh, add the following line to your .kshrc:

PS1='$PWD '

In csh, add the following lines to your .cshrc: (You do not need to add the lines that start with #. These are comments.)
# make a command doprompt that sets the prompt to the working directory
alias doprompt 'set prompt="`pwd` "'
# set the prompt the first time around
doprompt
# alias the cd command to change directories and reset the prompt
alias cd 'chdir !* || doprompt'
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 4 895
7 janv. 2009 à 20:31
Est-ce qu'une fois les changements effectués, tu source ton fichier .profile (ou autre) pour les faire prendre en compte ? (source ~/.profile)

Ou est-ce que tu relances ta session au pire ?
0
Je sauvegardais mes changements et je fermais ma session.. et ouverture d'une nouvelle session..

ce que je ne comprends toujours pas, est que $PWD est vide.. En tant normal il devrait contenir quelque chose. et en temps normal la commande PS1=' $PWD ' devrait fonctionner.
0
royinfo > royinfo
8 janv. 2009 à 14:40
Je n'ai toujours pas trouve.
0
jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 4 895 > royinfo
8 janv. 2009 à 15:12
Donnes-nous les résultats des commandes demandées au post #7 et affiche le contenu du fichier "/etc/profile"
0
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
8 janv. 2009 à 15:15
hello
en Bourne sh, ceci doit fonctonner
nd() { cd $* ; PS1="`pwd` "; }
je crois me rappeller qu'il faut respecter l'espace entre ; et }, ajouter dans $HOME/.profile
et faire
. $HOME/.profile
il n'y a pas de source et de ~ en Bourne sh
0
Reponse pour JIPICY

root->echo $SHELL
/bin/sh


Si je fais : nd() { cd $* ; PS1="`pwd` "; } cela implique que par la suite il faut utiliser la commande nd et non cd pour changer de repertoire.. C'est moch en maudit... il y a t'il une autre solution ?

merci a vous tous.
0
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
8 janv. 2009 à 16:03
pas en Bourne sh
il faut utiliser un alias,soit en csh ou en ksh ou en bash, il n'y a pas d'alias en sh
0