[bash linux] etendre $0 en chemin d'acces

Fermé
santiago69 Messages postés 477 Date d'inscription mercredi 7 mars 2001 Statut Membre Dernière intervention 12 septembre 2016 - 27 mai 2008 à 12:18
dubcek Messages postés 18724 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 15 mai 2024 - 27 mai 2008 à 13:07
Salut a tous,

Dans un script bash, la variable $0 renvoie le fichier lui meme. Mais comment faire pour obtenir son chemin d'acces.

Par exemple en DOS windows,
%~dp0    renvoi le chemin d'acces au fichier
%~nx0    renvoi le nom et l'extension du fichier


Quelles seraient les syntaxes equivalentes en bash linux ?

Merci d'avance
Santiago

3 réponses

macgawel Messages postés 664 Date d'inscription mercredi 7 mai 2008 Statut Membre Dernière intervention 1 novembre 2008 89
27 mai 2008 à 12:27
Bonjour.

Tu peux essayer :
repertoire=$(pwd)
1
santiago69 Messages postés 477 Date d'inscription mercredi 7 mars 2001 Statut Membre Dernière intervention 12 septembre 2016 209
27 mai 2008 à 12:30
pas exactement : la commande pwd renvoi le chemin courant.
or ce dont j'ai besoin, c'est le chemin du script en cours.

merci quand meme
santiago
0
macgawel Messages postés 664 Date d'inscription mercredi 7 mai 2008 Statut Membre Dernière intervention 1 novembre 2008 89
27 mai 2008 à 12:44
C'est vrai... :-O

Il y a peut-être (certainement) plus simple, mais ça marche !

cd $(dirname $0)
rep=$(pwd)
cd -
0
dubcek Messages postés 18724 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 15 mai 2024 5 615
27 mai 2008 à 13:07
hello
et avec
whereis $(basename $0)
0