-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArchivos.sh
64 lines (49 loc) · 1.43 KB
/
Archivos.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Crear archivos y directorios
input_type=""
input_name=""
input_text=""
read -p "Desea generar un directorio (1) o un archivo (2)? " input_type
case $input_type in
1)
read -p "Ingrese el nombre del directorio: " input_name
# Evualuar si ya existe el directorio
if [[ -d $input_name ]]; then
echo "El directorio ya existe"
exit 0
fi
mkdir -m 755 "$input_name"
# Validar si el último comando funcionó correctamente
if [[ $? -ne 0 ]]; then
echo "Error al crear el directorio"
exit 1
fi
;;
2)
read -p "Ingrese el nombre del archivo: " input_name
# Evualuar si ya existe el archivo
if [[ -f "$input_name" ]]; then
echo "El archivo ya existe"
exit 0 # Salir del programa
fi
touch "$input_name"
if [[ $? -ne 0 ]]; then
echo "Error al crear el archivo"
exit 1
fi
chmod 644 "$input_name"
read -p "Ingrese el texto para el archivo $input_name: " input_text
echo "$input_text" >> "$input_name"
if [[ $? -ne 0 ]]; then
echo "Error al agregar el texto"
exit 1
fi
cat "$input_name"
if [[ $? -ne 0 ]]; then
echo "Error al leer el archivo"
fi
;;
*)
echo "Opción fuera de rango"
;;
esac