Les Allergies
Alimentaires
Posez votre question Signaler

$PWD sur unix

royinfo - Dernière réponse le 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
Lire la suite 

$PWD sur unix »

Suggestions
18 réponses
Réponse
+0
moins plus
Salut,
PS1="[\u ->\w] # "
Si tu veux que ce soit permanent tu mets ça dans le .bashrc du "root" :
PS1="[\u ->\w] # "
export PS1
royinfo - 7 janv. 2009 à 17:24
Bonjour, je viens tout juste d'executer la commande mentionnee PS1="[\u ->\w] # " et le resultat est :


[\u ->\w] #
Ajouter un commentaire
Réponse
+0
moins plus
[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 ?
fsaelens - 7 janv. 2009 à 18:07
pour connaître ton shell, tape ps, il devrait apparaître en première ligne (j'espère).
royinfo - 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->/
fsaelens - 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.
Ajouter un commentaire
Réponse
+0
moins plus
echo $SHELL
Pour connaitre ton shell de connexion ou
grep $USER /etc/passwd
Sinon, affiche le contenu du ".profile".
royinfo - 7 janv. 2009 à 18:37
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->
Ajouter un commentaire
Réponse
+0
moins plus
http://osr507doc.sco.com/en/OSTut/Customizing_your_environment.html
royinfo - 7 janv. 2009 à 20:19
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'
Ajouter un commentaire
Réponse
+0
moins plus
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 ?
royinfo - 7 janv. 2009 à 20:43
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.
royinfo - 8 janv. 2009 à 14:40
Je n'ai toujours pas trouve.
jipicy- 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"
Ajouter un commentaire
Réponse
+0
moins plus
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
Ajouter un commentaire
Réponse
+0
moins plus
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.
dubcek- 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
Ajouter un commentaire
Ce document intitulé « $PWD sur unix » issu de CommentCaMarche (www.commentcamarche.net) est mis à disposition sous les termes de la licence Creative Commons. Vous pouvez copier, modifier des copies de cette page, dans les conditions fixées par la licence, tant que cette note apparaît clairement.
Dossier à la une
Passage au tout numérique : quel coût pour les particuliers ?