cd pwd cat <file> who sort <file> grep <string> <file>
bach 9% cat > foo
4 ert
6 yui
2 ert
9 rtdy
1 ert
bach 10% sort foo
1 ert
2 ert
4 ert
6 yui
9 rtdy
ls -l ls -a head -# <file>
tail +#deb <file> tail -#end <file>
wc -[clw] <file>
* ? [abc] [a-zA-Z]
ls > foo
wc foo > bar
ls -l >> foo
bach 23% sort
2 ert # lecture au clavier
3 eyt
4 rtuy
9 uyi
5 rty
1 rty
^D
1 rty # resultat de sort
2 ert
3 eyt
4 rtuy
5 rty
9 uyi
cat > foo
bach 36% tr e E < foo > sss
bach 37% cat foo
4 ert
6 yui
2 ert
9 rtdy
1 ert
bach 38% cat sss
4 Ert
6 yui
2 Ert
9 rtdy
1 Ert
who | sort
who | grep X
grep <mot> <file> | wc - l
e=/etc sh
set e=/etc csh
echo $e
ls $e
ls $e/rmt
path home shell prompt mail term user csh
PATH HOME SHELL MAIL sh
set e=`pwd`
cd ....
cd $e
who | wc -l in combien
csh combien
chmod u+x combien
combien
grep $1 $2 | wc -l in occur
csh occur <mot> <file>
$1 - $9
$0 le nom de la commande
$# le nombre d'arguments sh seulement
$* l'ensemble des arguments
cat $1 > $3 in concat
cat $2 >> $3
echo $# in nbargs
nbargs * compte le nb de fichiers
nbargs *.c
set i = $1 in occur
shift
grep $i $* | wc -l
test -f x file
test -d x directory
test -[rwx] f droits en lecture, ecriture et execution
test str chaine non vide
test str1 = str2 (in)egalite de chaines
test str1 != str2
test n1 -eq n2 (in)egalite de nombres
test n1 -neq n2
-ge -gt -le -lt
test ! x NON logique
test x -a y ET logique
test x -o y OU logique
test -r foo -a -w teste droits lecture et ecriture
test ! -r foo
if test -f $1
then echo $1 est un fichier
else echo $1 est un repertoire
fi
if test $# -eq 2
then sort $1 > $2
else echo nb d arguments incorrect
fi
if test ! -f $1 -a ! -d $1 creer un fichier si n'existe pas
then > $1
else ls -l $1
fi
if test -d $HOME/../$1 tester si qqn est un utilisateur
then echo $1 est connu
else echo $1 est inconnu
fi
case $1 in
-l) echo Liste des fichiers Lisp ; ls *.lsp ;;
-c) echo Liste des fichiers C ; ls *.c ;;
-a) echo Liste de tous les fichiers ; ls ;;
*) echo Option inconnue ;;
esac
case $1 in
-r) option=lecture ;;
-w) option=ecriture ;;
-x) option=execution ;;
esac
if test $1 $2
then echo $2 a les droits de $option
else echo $2 n a pas les droits de $option
fi
for i in *
do
if test -f $i
then echo $i est un fichier
else if test -d $i
then echo $i est un repertoire
else echo $i est un autre fichier
fi
fi
done
for i in * droits d execution differencies
do
if test -f $i
then chmod a+x $i
else chmod o-x $i
fi
done
f=$1 concatenation
shift
for i in $*
do
echo $i >> $f ; cat $i >> $f
done
while test $1 parcours des args
do
echo $1 ; shift
done
addition:
#!/bin/bash
echo ADTITIONS
read i j
while test $i
do
echo -n $i + $j =" "
echo $[$i+$j]
read i j
done
echo Additions faites
file2:
3 5
7 5
2 9
cat file2 | addition
ADTITIONS
3 + 5 = 8
7 + 5 = 12
2 + 9 = 11
Additions faites
Date : formattage de la date
format `date `
format :
case $1 in
Mon) j=lundi ;;
Tue) j=mardi ;;
Wen) j=mercredi ;;
Thu) j=jeudi ;;
Fri) j=vendredi ;;
Sat) j=samedi ;;
Sun) j=dimanche ;;
esac
echo Nous sommes le $j $3 $2 $6. Il est $4
tel : recherche d'un no de tel
arg2 `rep $1`
rep :
grep $1 A/tel
arg2 :
echo $2
A/tel =
pierre 45
jean 56
thyerry 76
anne 23
listemots : liste des mots d'un fichier
lesmots `cat $1`
lesmots :
mots $* | sort | uniq
mots :
for i in $*
do
echo $i
done
x=`who | grep $1 | wc -l` tester si qqn est logge
if test $x -ge 1
then echo $1 est logge
else
echo $1 n est pas logge
fi
r='1' factorielle en shell
i=$1
while test $i -gt 1
do
r=`expr $r \* $i`
i=`expr $i - 1`
done
echo $r
somme : nb d'objets possedes par une pers.
somme2 `grep $1 B/objets`
somme2
res='0'
while test $1
do
res=`expr $res + $3`
shift ; shift ; shift
done
echo $res
B/objets =
jean livres 50
pierre livres 67
jean cassettes 23
pierre films 12
jacques films 43
pierre disques 87
fib : fibonacci recursif
if test $1 -le '1'
then expr '1'
else x=`expr $1 - '1'`
y=`expr $1 - '2'`
x=`fib $x`
y=`fib $y`
expr $x + $y
fi
mfib : memo fibonacci
l=`cat memo.fib`
mf=`lookup $1 $l`
if test $mf
then echo $mf
else if test $1 -le '1'
then echo '1'
else x=`expr $1 - '1'`
y=`expr $1 - '2'`
x=`mfib $x`
y=`mfib $y`
z=`expr $x + $y`
echo $1 $z >> memo.fib
echo $z
fi
fi
lookup :
n=$1
shift
while test $1
do
if test $1 -eq $n
then break
else shift ; shift
fi
done
if test $1
then echo $2
fi
memo.fib = apres calcul de mfib 10 (vide au depart)
2 2
3 3
4 5
5 8
6 13
7 21
8 34
9 55
10 89