[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.
Diferencias
Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previaPróxima revisiónAmbos lados, revisión siguiente | ||
es:howtos:general_admin:cli_constructs_and_useful_info [2019/02/07 16:01 (UTC)] – [Construye] slackwarespanol | es: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> | <note warning> | ||
- | ====== Construcciones de CLI e información útil ====== | + | ====== Construcciones de CLI (Interfaz de línea de comandos) |
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. | ||
</ | </ | ||
- | Las opciones '' | + | Las opciones |
<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 a time. Here 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 |
<code bash> | <code bash> | ||
base=" | base=" | ||
Línea 64: | Línea 64: | ||
done | done | ||
</ | </ | ||
- | Also note that '' | + | También tenga en cuenta que '' |
=== 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 | ||
</ | </ | ||
- | You can also use '' | + | También puede usar '' |
<code bash> | <code bash> | ||
for i in $(seq 1 100) | for i in $(seq 1 100) | ||
Línea 80: | Línea 80: | ||
done | done | ||
</ | </ | ||
- | Note that there are no quotes around | + | Tenga en cuenta que no hay comillas alrededor de '' |
- | == External Links === | + | == Enlaces externos |
- | * http:// | + | |
- | ==== Quoting | + | ==== Comilla |
- | Quoting may seem complicated, and reasons for it obscure, but there is a purpose to it and it is not that complicated. | + | Las comillas pueden parecer complicadas, y las razones de ello son oscuras, pero tiene un propósito y no es tan complicado. |
- | === Double quoting | + | === Doble comillas |
- | The reason for double quoting is to preserve spaces, like spaces in file names. Double quoting a variable | + | La razón para la comilla doble es para preservar espacios, como espacios en nombres de archivos. La doble cita de una variable |
<code bash> | <code bash> | ||
bash-4.2$ ls | bash-4.2$ ls | ||
Línea 100: | Línea 100: | ||
bash-4.2$ | bash-4.2$ | ||
</ | </ | ||
- | Clearly you need to quote a file with spaces. You could use single quotes here, because | + | Claramente necesitas encomillar un archivo con espacios. Puede usar comillas simples aquí, porque |
<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$ | ||
</ | </ | ||
- | Nor should you quote in any case where a command requires multiple | + | Tampoco debe encomillar en ningún caso en que un comando requiera múltiples |
< | < | ||
bash-4.2$ ls | bash-4.2$ ls | ||
Línea 130: | Línea 130: | ||
bash-4.2$ | bash-4.2$ | ||
</ | </ | ||
- | Also note that you can and should quote within command substitutions, as shown by the '' | + | También tenga en cuenta que puede y debe encomillar dentro de las sustituciones de comandos, como se muestra en el ejemplo anterior " |
<code bash> | <code bash> | ||
mkdir " | mkdir " | ||
</ | </ | ||
- | This makes a directory within the current directory called the same name as the current directory. If '' | + | Esto crea un directorio dentro del directorio actual llamado el mismo nombre que el directorio actual. Si '' |
- | === Single quoting | + | === Comilla simple |
- | The reason for single quoting is to escape special characters from the shell, | + | La razón para la comilla simple es para escapar caracteres especiales de la shell, |
<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$ | ||
</ | </ | ||
- | Here the shell expands | + | Aquí el sehell se expande |
- | === External Links === | + | === Enlaces externos |
* http:// | * http:// | ||
- | ==== Regular expressions | + | ==== Expresiones regulares |
- | === Basic === | + | === Básico |
- | * '' | + | * '' |
- | * '' | + | |
- | < | + | < |
< | < | ||
bash-4.2$ cat test.txt | bash-4.2$ cat test.txt | ||
Línea 167: | Línea 167: | ||
test | test | ||
</ | </ | ||
- | | + | |
- | * '' | + | |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * Example: '' | + | * '' |
- | * '' | + | |
+ | * '' | ||
=== 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 '' | The following must be supported by the program for them to work. For example for grep you must run '' |