Script

Résolu/Fermé
cycloop Messages postés 69 Date d'inscription mercredi 22 octobre 2008 Statut Membre Dernière intervention 8 avril 2013 - 6 nov. 2009 à 09:46
lami20j Messages postés 21331 Date d'inscription jeudi 4 novembre 2004 Statut Modérateur, Contributeur sécurité Dernière intervention 30 octobre 2019 - 6 nov. 2009 à 13:42
Bonjour,
J'ai créé un script que j'ai mis dans /usr/bin et que j'ai "chmodé" correctement.
voilà le code:

#!/bin/bash

clear
cd $1
ls -l

Petit problème (auquel je m'attendais un peu, je ne vous le cache pas) : lorsqu'on fait cd dans un script, ce n'est actif que dans le script... est-ce que quelqu'un sait comment dire "ce cd là il faut qu'il change le répertoire de l'utilisateur" ?

Merci d'avance
Cycloop
A voir également:

4 réponses

dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
6 nov. 2009 à 12:27
hello
créer une fonction et un alias

ccd() { clear;\cd $1;ls -l ; }
alias cd=ccd

pour supprimer l'alias : unalias cd
pour supprimer la fonction : unset -f ccd
0
cycloop Messages postés 69 Date d'inscription mercredi 22 octobre 2008 Statut Membre Dernière intervention 8 avril 2013 16
6 nov. 2009 à 12:34
merci pour ta réponse :)
cette fonction est à placer dans .bashrc ?
0
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
6 nov. 2009 à 13:13
oui si tu veux qu'elle soit permanente
0
lami20j Messages postés 21331 Date d'inscription jeudi 4 novembre 2004 Statut Modérateur, Contributeur sécurité Dernière intervention 30 octobre 2019 3 567
6 nov. 2009 à 13:42
Salut,
lami20j@debian:~/trash$ cat a.sh
#!/bin/bash

cd $1
ls -l
lami20j@debian:~/trash$ chmod +x a.sh
lami20j@debian:~/trash$ ls -l a.sh
-rwxr-xr-x 1 lami20j lami20j 25 nov  6 13:36 a.sh
lami20j@debian:~/trash$ pwd
/home/lami20j/trash
lami20j@debian:~/trash$ . ./a.sh /home/lami20j/trash2
total 22356
-rwxr-xr-x 1 lami20j lami20j        0 nov 24  2007 a.c
-rwxr-xr-x 1 lami20j lami20j     6841 aoû 24 18:42 a.out
-rwxr-xr-x 1 lami20j lami20j        0 nov 24  2007 b.c
-rwxr-xr-x 1 lami20j lami20j       81 déc 21  2007 ccm.sh
drwxr-xr-x 2 lami20j lami20j     4096 oct 18 14:24 exxan
-rwxr-xr-x 1 lami20j lami20j      997 mar 14  2008 ficatore2.pl
-rwxr-xr-x 1 lami20j lami20j      779 mar 13  2008 ficatore_last.pl
-rwxr-xr-x 1 lami20j lami20j    26013 nov 27  2007 jeff_astuce_192.168.0.1.odp
-rwxr-xr-x 1 lami20j lami20j     4152 nov 27  2007 jeff.original
-rwxr-xr-x 1 lami20j lami20j    68509 nov 27  2007 lan1.png
-rwxr-xr-x 1 lami20j lami20j    66596 nov 27  2007 lan2.png
-rwxr-xr-x 1 lami20j lami20j    67955 nov 27  2007 lan3.png
-rwxr-xr-x 1 lami20j lami20j     1041 mar 14  2008 last_ficatore.pl
-rwxr-xr-x 1 lami20j lami20j   193003 mar 13  2008 netmap.txt
-rwxr-xr-x 1 lami20j lami20j        0 nov 24  2007 nom.prenom.txt
drwxr-xr-x 9 lami20j lami20j     4096 nov  1 11:21 perl_dbi
-rwxr-xr-x 1 lami20j lami20j     3804 jan  6  2008 pnSession.rar
-rwxr-xr-x 1 lami20j lami20j    20691 mar 13  2008 telephone.txt
drwxr-xr-x 2 lami20j lami20j     4096 déc 20  2007 vider
drwxr-xr-x 2 lami20j lami20j     4096 déc 20  2007 vider2
drwxr-xr-x 2 lami20j lami20j     4096 aoû 10  2008 wmv
lami20j@debian:~/trash2$ pwd
/home/lami20j/trash2

0