Herramientas de usuario

Herramientas del sitio


informatica:certificaciones:lpic:lpic-1:105_shells_and_shell_scripting

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anteriorRevisión previa
Próxima revisión
Revisión previa
informatica:certificaciones:lpic:lpic-1:105_shells_and_shell_scripting [2022/03/21 10:34] tempwininformatica:certificaciones:lpic:lpic-1:105_shells_and_shell_scripting [2022/04/19 10:41] (actual) – [Test] tempwin
Línea 5: Línea 5:
 Veremos cómo configurar y usar el shell mediante el cual interactuamos con el sistema. En la segunda parte investigamos. Veremos cómo configurar y usar el shell mediante el cual interactuamos con el sistema. En la segunda parte investigamos.
  
-  * 105.1: Customizar y usar el entorno de Shell (4) +  * [[informatica:certificaciones:lpic:lpic-1:105_shells_and_shell_scripting:105.1_customize_and_use_the_shell_environment|105.1 Customize and use the shell environment]] (4) 
-  * 105.2: Customizar y escribir scripts (4)+  * [[informatica:certificaciones:lpic:lpic-1:105_shells_and_shell_scripting:105.2_customize_or_write_simple_scripts|105.2 Customize or write simple scripts]] (4)
  
 +===== Ejercicios =====
 +
 +**Ejercicio 1: Scripting**
 +
 +**Sube un documento con las respuestas a las siguientes actividades:
 +
 +Adjunte capturas de pantalla para ver los resultados
 +**
 +
 +==== PARTE I ====
 +
 +**Cree un script generador de ficheros que haga lo siguiente:**
 +
 +**1. nos pida un nombre de fichero y una ruta de destino**
 +
 +<code bash>
 +echo "Nombre de fichero: "
 +read filename
 +
 +echo "Ruta de creación: "
 +read path
 +</code>
 +
 +**2. nos pida un numero de ficheros**
 +
 +<code bash>
 +echo "Número de ficheros a crear:"
 +read num_files
 +</code>
 +
 +**3. nos cree ese número de ficheros, con el nombre especificado seguido de un número, en la ruta especificada**
 +
 +<code bash>
 +i=1
 +while [ $i -le $num_files ]
 +do
 +    touch $path/$filename-$i
 +    let i=i+1
 +done
 +</code>
 +
 +Script final:
 +
 +<code bash>
 +#!/bin/bash
 +
 +echo "Nombre de fichero: "
 +read filename
 +
 +echo "Ruta de creación: "
 +read path
 +
 +echo "Número de ficheros a crear:"
 +read num_files
 +
 +i=1
 +while [ $i -le $num_files ]
 +do
 +    touch $path/$filename-$i
 +    let i=i+1
 +done
 +</code>
 +==== PARTE II ====
 +
 +**Cree un script de shell que haga lo siguiente:**
 +
 +**1. mostrará una lista completa y completa (recursiva) del contenido de cualquier directorio que se le pase en la línea de comando** 
 +
 +<code bash>
 +dir=$1
 +
 +find $dir -print
 +</code>
 +
 +**2. mostrará un mensaje de error si el parámetro que le das no es un directorio.**
 +
 +<code bash>
 +if [ -d $dir ]
 +then
 +    find $dir -print
 +else
 +    echo "$dir no es un directorio"
 +fi
 +</code>
 +
 +**3. Probar el script para que muestre los resultados con un directorio válido y y forzar el error con un nombre de directorio no existente**
 +
 +Script completo:
 +
 +<code bash>
 +#!/bin/bash
 +
 +dir=$1
 +
 +# Comprobar si es un directorio
 +if [ -d $dir ]
 +then
 +    find $dir -print
 +else
 +    echo "$dir no es un directorio"
 +    exit 1
 +fi
 +</code>
 +
 +===== Test =====
 +
 +**Every shell script intended to run within a bash environment, should have what identifier at the top of the script file?** 
 +
 +  * ''#/bin/bash''
 +  * ''!/bin/bash''
 +  * ''!#/bin/bash''
 +  * ''#!/bin/bash'' (**solución**) 
 +
 +**Of the following conditional statements within a shell script, which one will test for the existence of a file called 'mytest.txt' in the current directory?**
 +
 +  * ''if [[$FILE is 'mytest.txt' ]];then''
 +  * ''if [[ $1='mytest.txt' ]];then''
 +  * ''if [[ -f mytest.txt ]];'' (**solución**) 
 +  * ''if [[ filename='mytest.txt' ]]; then''
 +
 +**What user script (if it exists) is run, from a user's home directory, every time they log into a system? (select 2)**
 +
 +  * ''~/.bash_profile'' (**solución**) 
 +  * ''/etc/rc.local''
 +  * ''/etc/rc.local''
 +  * ''~/.bashrc'' (**solución**) 
 +
 +**Which of the following special shells that, when assigned to a user account as the default shell, will prevent that account from being able to log in? (Choose the 2 correct answers)**
 +
 +  * ''. /etc/users.deny''
 +  * ''/sbin/nologin'' (**solución**) 
 +  * ''/etc/users.allow''
 +  * ''/bin/false'' (**solución**) 
 +
 +**Which of the following variable definitions will be available to subshells in the environment?**
 +
 +  * ''export MYVAR="Some Value"'' (**solución**) 
 +  * ''MYVAR="Some Value"''
 +  * ''env MYVAR="Some Value"''
 +  * None of the Above
  
informatica/certificaciones/lpic/lpic-1/105_shells_and_shell_scripting.1647855244.txt.gz · Última modificación: por tempwin