[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

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
Próxima revisiónAmbos lados, revisión siguiente
es:howtos:general_admin:cli_constructs_and_useful_info [2019/02/07 16:01 (UTC)] – [Construye] slackwarespanoles:howtos:general_admin:cli_constructs_and_useful_info [2019/02/07 19:53 (UTC)] – [Regular expressions] slackwarespanol
Línea 1: Línea 1:
 <!-- Add your text below. We strongly advise to start with a Headline (see button bar above). --> <!-- Add your text below. We strongly advise to start with a Headline (see button bar above). -->
 <note warning>En proceso de traducción. Victor</note> <note warning>En proceso de traducción. Victor</note>
-====== Construcciones de CLI e información útil ======+====== Construcciones de CLI (Interfaz de línea de comandos) e información útil ======
 El propósito de este artículo no es ser un tutorial de CLI, sino más bien ser una exposición de construcciones comunes utilizadas en shell scripting para lograr un objetivo de manera eficiente. También hay secciones que simplemente ayudan a entender un tema determinado. El propósito de este artículo no es ser un tutorial de CLI, sino más bien ser una exposición de construcciones comunes utilizadas en shell scripting para lograr un objetivo de manera eficiente. También hay secciones que simplemente ayudan a entender un tema determinado.
 ==== Construye ==== ==== Construye ====
Línea 37: Línea 37:
 column three contains lines common to both files. column three contains lines common to both files.
 </code> </code>
-Las opciones '' -1 '' '' -2 '' '' -3''suprimen las columnas respectivas. Supongamos que desea registrar los archivos que se agregaron a '' /usr'' después de ejecutar el comando '' $ 1 '':+Las opciones '' '-1' '' '' '-2' '' '' '-3''' suprimen las columnas respectivas. Supongamos que desea registrar los archivos que se agregaron a '' /usr'' después de ejecutar el comando '' $ 1 '':
 <code bash> <code bash>
 # before, make install, after # before, make install, after
Línea 55: Línea 55:
  
 === while read line === === while read line ===
-This construct is common and is useful for reading files or stdin one line at timeHere is an example that can be used to concatenate split files in order:+Esta construcción es común y es útil para leer archivos o ingresar una línea la vezAquí hay un ejemplo que se puede usar para concatenar archivos divididos en orden:
 <code bash> <code bash>
 base="$(echo "$@" | rev | cut -d. -f1 --complement | rev)" base="$(echo "$@" | rev | cut -d. -f1 --complement | rev)"
Línea 64: Línea 64:
 done done
 </code> </code>
-Also note that ''sort -V'' is a version sort and is useful in cases where ''ls'' sorts suffixes incorrectlyThe usual way to prevent this is to name numbered suffixes with ''0'' padding like ''file.001'', but it may overflow and this is why ''sort -V'' is useful.+También tenga en cuenta que '' sort -V '' es una clasificación de versión y es útil en los casos en que '' ls '' ordena los sufijos de forma incorrectaLa forma habitual de evitar esto es nombrar sufijos numerados con '' 0 '' como '' file.001 '', pero puede desbordarse y es por eso que '' sort -V '' es útil.
 === for i in === === for i in ===
-Here is an example for extracting all rpms in a directory:+Aquí hay un ejemplo para extraer todos los rpms en un directorio:
 <code bash> <code bash>
 for i in *.rpm for i in *.rpm
Línea 73: Línea 73:
 done done
 </code> </code>
-You can also use ''seq'' to make ''i'' a loop counter:+También puede usar '' seq '' para hacer que '' i '' sea un contador de bucle:
 <code bash> <code bash>
 for i in $(seq 1 100) for i in $(seq 1 100)
Línea 80: Línea 80:
 done done
 </code> </code>
-Note that there are no quotes around ''$(seq)'' because otherwise it would quote the entire expanded number sequence and that wouldn't work right+Tenga en cuenta que no hay comillas alrededor de '' $ (seq) '' porque de lo contrario, citaría la secuencia numérica completa y eso no funcionaría bien
-== External Links === +== Enlaces externos === 
-  * http://www.commandlinefu.com/commands/browse +   * http://www.commandlinefu.com/commands/browse 
-==== Quoting ==== +==== Comilla ====  
-Quoting may seem complicatedand reasons for it obscurebut there is a purpose to it and it is not that complicated.  +Las comillas pueden parecer complicadasy las razones de ello son oscuraspero tiene un propósito y no es tan complicado.  
-=== Double quoting === +=== Doble comillas ===  
-The reason for double quoting is to preserve spaceslike spaces in file namesDouble quoting a variable or command substitution makes it into a single argumentAn example:+La razón para la comilla doble es para preservar espacioscomo espacios en nombres de archivosLa doble cita de una variable o una sustitución de comando lo convierte en un solo argumentoUn ejemplo:
 <code bash> <code bash>
 bash-4.2$ ls bash-4.2$ ls
Línea 100: Línea 100:
 bash-4.2$  bash-4.2$ 
 </code> </code>
-Clearly you need to quote a file with spacesYou could use single quotes herebecause no variables were inside the quotesYou should not quote in this case:+Claramente necesitas encomillar un archivo con espaciosPuede usar comillas simples aquíporque no hay variables dentro de las comillasNo debes encomillar en este caso:
 <code bash> <code bash>
 bash-4.2$ for i in $(seq 1 10); do printf "$i "; done; echo;   bash-4.2$ for i in $(seq 1 10); do printf "$i "; done; echo;  
Línea 117: Línea 117:
 bash-4.2$  bash-4.2$ 
 </code> </code>
-Nor should you quote in any case where a command requires multiple variables and you give them to it inside one quoted variable. A quoted variable is then taken as the only argumentrather than multiple argumentsAn example:+Tampoco debe encomillar en ningún caso en que un comando requiera múltiples variables y se las asigne dentro de una variable encomilladaUna variable encomillada se toma entonces como el único argumentoen lugar de múltiples argumentosUn ejemplo:
 <code> <code>
 bash-4.2$ ls bash-4.2$ ls
Línea 130: Línea 130:
 bash-4.2$  bash-4.2$ 
 </code> </code>
-Also note that you can and should quote within command substitutionsas shown by the ''replace a suffix'' example above and:+También tenga en cuenta que puede y debe encomillar dentro de las sustituciones de comandoscomo se muestra en el ejemplo anterior "reemplazar un sufijo" y:
 <code bash> <code bash>
 mkdir "$(basename "$(pwd)")" mkdir "$(basename "$(pwd)")"
 </code> </code>
-This makes a directory within the current directory called the same name as the current directoryIf ''pwd'' expands into something with spacesthe command will work+Esto crea un directorio dentro del directorio actual llamado el mismo nombre que el directorio actualSi '' pwd '' se expande en algo con espaciosel comando funcionará.  
-=== Single quoting === +=== Comilla simple ===  
-The reason for single quoting is to escape special characters from the shell, while passing them to command so it can use themYou should use single quotes for every argument passed to another program that contains shell characters to be interpreted by that program and **NOT** by the shell. Example:+La razón para la comilla simple es para escapar caracteres especiales de la shell, mientras se los pasa un comando para que pueda usarlosDebe usar comillas simples para cada argumento pasado a otro programa que contenga caracteres de shell para que sean interpretados por ese programa y ** NO ** por el shell. Ejemplo:
 <code bash> <code bash>
 bash-4.2$ find -name *.txt bash-4.2$ find -name *.txt
Línea 148: Línea 148:
 bash-4.2$  bash-4.2$ 
 </code> </code>
-Here the shell expands ''*'' before find sees itYou should single quote input to ''awk'', ''find'', ''sed'', and ''grep'', as each of these uses special characters that overlap with the shells'and thus they must be protected from shell expansion+Aquí el sehell se expande '' * '' antes de encontrarlaDebe ingresar la entrada de comillas a '' awk '', '' find '', '' sed '' '' grep '', ya que cada uno de ellos utiliza caracteres especiales que se superponen con las del shelly por lo tanto deben ser Protegido de la expansión del shell. 
-=== External Links ===+=== Enlaces externos ===
   * http://www.grymoire.com/Unix/Quote.html   * http://www.grymoire.com/Unix/Quote.html
-==== Regular expressions ==== +==== Expresiones regulares ==== 
-=== Basic === +=== Básico === 
-  * ''.'' matches any single character+  * ''. '' coincide con cualquier carácter individual
-  * ''\'' escapes the next character+   * '' \ '' evita del siguiente carácter
-<note>Remember to escape the ''.'' using ''\.'' if you want an actual ''.''+<note>Recuerde que debe evitar ''. '' usando '' \. '' Si quieres un verdadero ''. ''
 <code> <code>
 bash-4.2$ cat test.txt  bash-4.2$ cat test.txt 
Línea 167: Línea 167:
 test test
 </code></note> </code></note>
-  * ''[]'' is a class and matches anything inside the brakets for a single characterExamples:  +  
-    * ''[Yy]'' matches or y. +  * '' [ ] '' es una clase y combina cualquier cosa dentro de los corchetes para un solo personajeEjemplos  
-    * ''[a-z0-9]'' includes a rangeand in this case matches through and through 9. +    * '' [Yy] '' coincide con y.  
-    * ''[^a-z]'' negates the rangeso in this case it matches anything but through z. +    * '' [a-z0-9] '' incluye un rangoy en este caso coincide con a través de y de 9.  
-  * ''^'' matches the beginning of a lineExample: ''^a'' matches an a at the beginning of line+    * '' [^ a-z] '' niega el rangopor lo que, en este caso, se ajusta a cualquier cosa excepto a a z.  
-  * ''$'' matches the end of a lineExample: ''a$'' matches an a at the end of line+  * '' ^ '' coincide con el principio de una líneaEjemplo: '' ^ a '' coincide con una al principio de una línea.  
-  * ''\<'' matches the beginning of a wordExample: ''\<a'' matches an a at the beginning of word+  * '' $ '' coincide con el final de una líneaEjemplo: '' a $ '' coincide con una al final de una línea.  
-  * ''\>'' matches the end of a wordExample: ''a\>'' matches an at the end of a word+  * '' \ <'' coincide con el principio de una palabraEjemplo: '' \ <a '' coincide con una al principio de una palabra.  
-    Example: ''\<[tT]he\>'' matches the word ''the'' or ''The''+  * '' \> '' coincide con el final de una palabraEjemplo: '' a \> '' coincide con una al final de una palabra.  
-  * ''*'' matches any number of the previous character or nothing no characterExample: ''[0-9]*'' which will match any number of numbers. ''.*'' matches any number of anything.+   Ejemplo: '' \ <[tT] he \> '' coincide con la palabra '' el '' '' El ''   
 +  * '' * '' coincide con cualquier número del carácter anterior o nada ningún carácterEjemplo: '' [0-9] * '' que coincidirá con cualquier número de números. ''. * '' coincide con cualquier número de cualquier cosa.
 === Extended regular expressions === === Extended regular expressions ===
 The following must be supported by the program for them to work. For example for grep you must run ''egrep'' or ''grep -E''. The following must be supported by the program for them to work. For example for grep you must run ''egrep'' or ''grep -E''.
 es:howtos:general_admin:cli_constructs_and_useful_info ()