Developpement/23SCR/SCR08/SCR8.txt

105 lines
1.4 KiB
Plaintext

1/
a)
x=7;for ((i=1;i<=x;i++)); do echo $i; done
b)
#!/bin/bash
if [[ $# -lt 1 ]]
then
echo " Usage : $0 "
exit
fi
if [[ $1 -lt 0 ]]
then
echo " Argument must be positive ! "
exit
fi
for (( i=1 ; i<= $1 ; i++))
do
echo $i
done
exit
2/
#!/bin/bash
if [[ $# -lt 2 ]]
then
echo " Usage : $0 <NUM_ARG1> <NUM_ARG2>"
exit
fi
if [[ $1 -lt 0 ]]
then
echo " Arg1 must be positive ! "
exit
fi
if [[ $2 -lt 0 ]]
then
echo " Arg2 must be positive ! "
exit
fi
if [[ $1 -gt $2 ]]
then
echo " Arg1 must be less than Arg2 !"
exit
fi
for (( i = $1 ; i <= $2 ; i++))
do
for (( j = $1 ; j <= $2 ; j++))
do
echo -n $(( i * j ))
echo -ne $"\t"
done
echo -e $"\n"
done
exit
3/
a)
#!/bin/bash
if [[ $# -lt 2 ]]
then
echo " Usage : $0 <SCR_FILE> <DEST_FILE>"
exit
fi
if [[ ! -f $1 ]]
then
echo " FILE $1 Does not exist!"
exit
fi
if [[ -f $2 ]]
then
echo -n " FILE $2 already exists. Overwrite ? Yes/No --> "
read answer
if [[ $answer != "Yes" ]]
then
exit
fi
cp /dev/null $2
fi
for addr in $(cat $1)
do
x=$(expr substr $addr 1 8)
y=$(expr substr $addr 9 8)
z=$(expr substr $addr 17 8)
t=$(expr substr $addr 25 8)
echo "$((2#$x)).$((2#$y)).$((2#$z)).$((2#$t))" >> $2
done
exit
b)
1) read x; echo "$? x=$x" affiche : 0 x=7
2) read x; echo "$? x=$x" affiche : 0 x=
3) read x; echo "$? x=$x" affiche : 1 x=
read permet d'initialiser une valeur dans une variable