for i in 'ls $i'
do
if [ -f $i ]
then echo "fichier ok"
elif [ -d $i ]
then echo "dossier ok"
#je rajoute en plus les lien symbolique et bloc...
fi
done
Il fonctionne, mais ne m'indique pas les bon types, en effet le dossier contient un lien symbolique, et quand exécute le script, il m'indique que des fichiers et dossiers.
[22:04] <simon@nikita:~> % cat /tmp/test
#!/bin/sh
DIRECTORY="$1"
find $DIRECTORY -maxdepth 1 | while read FILE; do
if [ -L $FILE ]; then
# lien symbolique
printf "$FILE est un lien symbolique\n"
elif [ -d $FILE ]; then
# répertoire
printf "$FILE est un répertoire\n"
elif [ -f $FILE ]; then
# fichier simple
printf "$FILE est un fichier simple\n"
fi
done
[22:05] <simon@nikita:~> % /tmp/test android-studio
android-studio est un répertoire
android-studio/src est un répertoire
android-studio/android-studio-ide-135.1641136-linux.zip est un fichier simple
#!/bin/bash
for i in `ls $1`
do
if [ -a "$1$i" ]; then echo "Le fichier $i existe";fi
if [ -b "$1$i" ]; then echo "Le fichier $i est de type bloc";fi
if [ -c "$1$i" ]; then echo "Le fichier $i est de type caractère";fi
if [ -d "$1$i" ]; then echo "Le fichier $i est un répertoire";fi
if [ -f "$1$i" ]; then echo "Le fichier est de type normal";fi
if [ -L "$1$i" ]; then echo "Le fichier est de type lien symbolique";fi
if [ -S "$1$i" ]; then echo "Le fichier est de type Socket";fi
if [ -w "$1$i" ]; then echo "Le fichier est modifiable";fi
if [ -x "$1$i" ]; then echo "Le fichier est exécutable";fi
if [ -r "$1$i" ]; then echo "Le fichier est accessible en lecture";fi
done
- Edité par Mobius00 3 février 2015 à 22:14:05
Programme Shell
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
pour plus d'infos