Dernière mise à jour : 26/05/2016
Écrivez un script qui concatène deux fichiers dans un troisième. Contrôlez que les paramètres sont valides ainsi que la présence et les permissions des fichiers.
#!/bin/bash # (c) Sébastien Adam 2013 # Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage # dans les Mêmes Conditions 2.0 Belgique. E_BADNBRARGS=3 E_FILEDOESNTEXIST=4 E_FILENOTNORMAL=5 E_FILEUNREADABLE=6 E_TARGETALREADYEXISTS=7 E_TARGETNOTWRITABLE=8 if [[ $# -ne 3 ]] then echo "Usage: $0 source_1 source_2 target" exit $E_BADNBRARGS fi for i in 1 2 do FILENAME=${!i} if [[ ! -e $FILENAME ]] then echo "$0: $FILENAME doesn't exist" exit $E_FILEDOESNTEXIST fi if [[ ! -f $FILENAME ]] then echo "$0: $FILENAME isn't normal" exit $E_FILENOTNORMAL fi if [[ ! -r $FILENAME ]] then echo "$0: $FILENAME isn't readable" exit $E_FILEUNREADABLE fi done if [[ -e $3 ]] then echo "$0: $3 file already exists. Do you want to overwrite it? [y|n]" read REPLY if [[ $REPLY != "y" ]] then exit $E_TARGETALREADYEXISTS fi if [[ ! -w $3 ]] then echo "$0: $3 is not writable" exit $E_TARGETNOTWRITABLE fi fi cat $1 $2 > $3
© Sébastien Adam 1996 ~ 2023 - https://www.sebastienadam.be/ - .