[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: pipe como variable en bash



Buenas,

Gracias a todos, al final lo he hecho con "read":

rtl_fm -f 433500000 -s 200000 -r 96000 -g 19.7 2>/dev/null |
EfergyRPI_001 | bash /opt/MiScript.sh

#!/bin/bash

while read efergy
do
        vatios=$(echo $efergy | cut -c19-28)
        ...
done

Gracias y un saludo.

El día 6 de febrero de 2018, 17:55, Erick Ocrospoma
<zipper1790@gmail.com> escribió:
> Lo mejor que podrias hacer es comentar que es lo que quieres lograr, no como
> crees que debes hacerlo y no te funciona :-)
>
> Creo que te funcionaria como argumento si usas xargs:
>
> # rtl_fm -f 433500000 -s 200000 -r 96000 -g 19.7 2>/dev/null | Efergy |
> xargs MiScript.sh
>
> Luego capturas el argumento en una variable (dentro del script)
>
> On Sun, Feb 4, 2018 at 4:52 PM petrohs el compa obrero <petrohs@gmail.com>
> wrote:
>>
>> a mi se me ocurre
>>
>> export variable="$(rtl_fm -f 433500000 -s 200000 -r 96000 -g 19.7
>> 2>/dev/null | Efergy)";
>>
>> y ya podrias usar la variable dentro de MiScript.sh
>
>
> Otra forma también seria Esta de arriba, aunque debería ser ir asi:
>
> export variable=$(rtl_fm -f 433500000 -s 200000 -r 96000 -g 19.7 2>/dev/null
> | Efergy)
>
> Lo puedes guardar en el /etc/bash.bashrc, luego cargas dicha variable dentro
> de tu script asi (lo puedes poner debajo del shebang, la primera línea del
> script):
>
> #!/bin.bash
> . /etc/bash.bashrc
>
>>
>> On Sun, Feb 4, 2018 at 3:34 PM, fernando sainz
>> <fernandojose.sainz@gmail.com> wrote:
>>>
>>> El día 4 de febrero de 2018, 21:32, Josu Lazkano
>>> <josu.lazkano@gmail.com> escribió:
>>> > Buenas,
>>> >
>>> > Tengo un pequeño problema de scripting que no se como resolver.
>>> > Dispongo de un comando que me da el consumo eléctrico de mi casa:
>>> >
>>> > # rtl_fm -f 433500000 -s 200000 -r 96000 -g 19.7 2>/dev/null | Efergy
>>> >
>>> > Lo que quiero es redirigir esta salida a un script en bash y tratar la
>>> > salida como una variable. Algo así:
>>> >
>>> > # rtl_fm -f 433500000 -s 200000 -r 96000 -g 19.7 2>/dev/null | Efergy
>>> > | MiScript.sh
>>>
>>>
>>> >
>>> > El problema es que no se como capturar la variable, he probado con
>>> > "$1" pero solo sirve para argumentos.
>>> >
>>> > ¿Alguien me pude ayudar?
>>> >
>>> > Gracias por todo y un saludo.
>>> >
>>> > --
>>> > Josu Lazkano
>>> >
>>>
>>> No entiendo muy bien lo que preguntas.
>>> Creo que podrías poner en tu script llamadas a "read" (man bash) que
>>> lee una linea de la entrada estándar.
>>>
>>>
>>>        read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N
>>> nchars] [-p
>>>        prompt] [-t timeout] [-u fd] [name ...]
>>>               One line is read from the  standard  input,  or  from  the
>>> file
>>>               descriptor  fd supplied as an argument to the -u option,
>>> and the
>>>               first word is assigned to the first name, the second word
>>> to the
>>>               second  name, and so on, with leftover words and their
>>> interven‐
>>>               ing separators assigned to the last name.  If  there  are
>>> fewer
>>>               words read from the input stream than names, the remaining
>>> names
>>>               are assigned empty values.  The characters in IFS  are
>>> used  to
>>>               split  the  line  into words using the same rules the shell
>>> uses
>>>               for expansion (described above under Word Splitting).  The
>>> back‐
>>>               slash  character  (\)  may be used to remove any special
>>> meaning
>>>               for the next character read and for line continuation.
>>> Options,
>>>               if supplied, have the following meanings:
>>>
>>> S2.
>>>
>>
>>
>>
>> --
>> "Cada cual según sus fuerzas, cada quien según sus necesidades..."
>
> --
>
>
> Erick.
>
>
> -------------------------------------------
> IRC     :   zerick
> Blog    : http://zerick.me
> About :  http://about.me/zerick
> Linux User ID :  549567



-- 
Josu Lazkano


Reply to: