TP3 DOSI/SE #!/bin/csh # TP3 q1 echo "en parametres" set r = 0 @ r = $1 + $2 echo $r echo "au clavier" @ r = $< + $< echo $r #!/bin/csh # TP3 q2 if ($# != 3) then echo "il faut 3 args" else if ( $1 <= $2 && $1 <= $3) then echo $1 else if ( $2 <= $1 && $2 <= $3) then echo $2 else echo $3 endif endif endif #!/bin/csh # TP3 q3 set max = 0 set sum = 0 foreach fic ( * ) set info = ( `ls -ld $fic` ) @ sum = $sum + $info[5] if ( $info[5] > $max ) then @ max = $info[5] endif if ( ! $?min ) then set min = $info[5] endif if ( $info[5] < $min ) then @ min = $info[5] endif end echo max=$max min=$min sum=$sum # TP3 q4 : calcul de la factorielle # TP3 q5 set lu = $< set min = $lu set max = $lu set som = $lu set prod = $lu set n = 1 while ( $n <= 10 ) set lu = $< @ n++ if ( $lu < $min ) then @ min = $lu endif if ( $lu > $max ) then @ max = $lu endif @ som += $lu @ prod *= $lu end echo $som $prod $min $max # q6 #!/bin/csh # TD3 q6 set sum = 0 foreach fic ( * ) if ( -d $fic ) then cd $fic @ sum += `~/q6.csh` cd .. else set infos = (`ls -ld $fic`) @ sum += $infos[5] endif end echo $sum #!/bin/csh # q7 tri set tab = ( $< $< $< $< $< $< $< $< $< $< ) set res = ( 1 1 1 1 1 1 1 1 1 1 ) set idxA = 0 set found = 0 set idxB = 1 while ( $idxB <= 10 ) @ idxA = 1 @ found = -1 while ( $idxA <= 10 ) if ($tab[$idxA] != -1) then if ( $found == -1 ) then @ found = $idxA endif if ( $tab[$found] > $tab[$idxA] ) then @ found = $idxA endif endif @ idxA++ end @ res[$idxB] = $tab[$found] @ tab[$found] = -1 @ idxB++ end echo $res #!/bin/csh # q8 q9 q10 compression set taille = 0 foreach fic ( *.Z ) set infos = (`ls -l $fic`) @ taille = $infos[5] uncompress $fic gzip $fic:r set infos = (`ls -l $fic:r.gz`) @ taille -= $infos[5] echo gain $taille octets end rm -f core.* *~ foreach fic ( * ) if ( -d $fic ) then cd $fic q6.csh cd .. endif end #!/bin/csh # q11 conversion de date #set thedate = ( `date` ) set thedate = ( Fri Apr 7 15:59:10 MET DST 1995 ) set lejour = ( Lundi Mardi Mercredi Jeudi Vendredi Samedi Dimanche ) set i = 1 foreach day ( Mon Tue Wen Thu Fri Sat Sun ) if ( $thedate[1] == $day ) then echo -n $lejour[$i] else @ i++ endif end echo -n " $thedate[3] " set lemois = ( janvier fevrier mars avril mai juin juillet aout septembre octobre novembre decembre ) @ i = 1 foreach month ( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ) if ( $thedate[2] == $month ) then echo -n $lemois[$i] else @ i++ endif end echo " $thedate[7], il est $thedate[4]"