Reference the stdin sent from piped sender process

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Say I have this:



delete_lock () 
if grep -q 'PATTERN'; then
# some command here
fi
cat >/dev/null


node foo.js | delete_lock


say the node.js process writes "foodog" to delete_lock, or it sends "sandbag". (It could be any unique name...)



How can I read that in the delete_lock function? delete_lock is going to receive some unique name and then delete the lock with that name from the filesystem...how can I do that?



The only thing that I can guess, is something like this:



 delete_lock () 
if grep -q 'lockname:xxx'; then
release_lock $xxx
fi
cat >/dev/null



but how do I reference the variable $xxx lol?







share|improve this question















  • 2




    Does the Node application produce a single line with a value that you want to capture, or is it a long stream that you don't want to interrupt but you'd like to find a pattern in and use it?
    – Kusalananda
    Apr 20 at 20:34






  • 2




    if xxx=$(grep -o 'pattern'); then ...; fi
    – jordanm
    Apr 20 at 20:55










  • @Kusalananda probably ongoing stream, not just one line, but it would be nice to know how to do it in both scenarios
    – Alexander Mills
    Apr 20 at 20:57














up vote
0
down vote

favorite












Say I have this:



delete_lock () 
if grep -q 'PATTERN'; then
# some command here
fi
cat >/dev/null


node foo.js | delete_lock


say the node.js process writes "foodog" to delete_lock, or it sends "sandbag". (It could be any unique name...)



How can I read that in the delete_lock function? delete_lock is going to receive some unique name and then delete the lock with that name from the filesystem...how can I do that?



The only thing that I can guess, is something like this:



 delete_lock () 
if grep -q 'lockname:xxx'; then
release_lock $xxx
fi
cat >/dev/null



but how do I reference the variable $xxx lol?







share|improve this question















  • 2




    Does the Node application produce a single line with a value that you want to capture, or is it a long stream that you don't want to interrupt but you'd like to find a pattern in and use it?
    – Kusalananda
    Apr 20 at 20:34






  • 2




    if xxx=$(grep -o 'pattern'); then ...; fi
    – jordanm
    Apr 20 at 20:55










  • @Kusalananda probably ongoing stream, not just one line, but it would be nice to know how to do it in both scenarios
    – Alexander Mills
    Apr 20 at 20:57












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Say I have this:



delete_lock () 
if grep -q 'PATTERN'; then
# some command here
fi
cat >/dev/null


node foo.js | delete_lock


say the node.js process writes "foodog" to delete_lock, or it sends "sandbag". (It could be any unique name...)



How can I read that in the delete_lock function? delete_lock is going to receive some unique name and then delete the lock with that name from the filesystem...how can I do that?



The only thing that I can guess, is something like this:



 delete_lock () 
if grep -q 'lockname:xxx'; then
release_lock $xxx
fi
cat >/dev/null



but how do I reference the variable $xxx lol?







share|improve this question











Say I have this:



delete_lock () 
if grep -q 'PATTERN'; then
# some command here
fi
cat >/dev/null


node foo.js | delete_lock


say the node.js process writes "foodog" to delete_lock, or it sends "sandbag". (It could be any unique name...)



How can I read that in the delete_lock function? delete_lock is going to receive some unique name and then delete the lock with that name from the filesystem...how can I do that?



The only thing that I can guess, is something like this:



 delete_lock () 
if grep -q 'lockname:xxx'; then
release_lock $xxx
fi
cat >/dev/null



but how do I reference the variable $xxx lol?









share|improve this question










share|improve this question




share|improve this question









asked Apr 20 at 20:31









Alexander Mills

1,885929




1,885929







  • 2




    Does the Node application produce a single line with a value that you want to capture, or is it a long stream that you don't want to interrupt but you'd like to find a pattern in and use it?
    – Kusalananda
    Apr 20 at 20:34






  • 2




    if xxx=$(grep -o 'pattern'); then ...; fi
    – jordanm
    Apr 20 at 20:55










  • @Kusalananda probably ongoing stream, not just one line, but it would be nice to know how to do it in both scenarios
    – Alexander Mills
    Apr 20 at 20:57












  • 2




    Does the Node application produce a single line with a value that you want to capture, or is it a long stream that you don't want to interrupt but you'd like to find a pattern in and use it?
    – Kusalananda
    Apr 20 at 20:34






  • 2




    if xxx=$(grep -o 'pattern'); then ...; fi
    – jordanm
    Apr 20 at 20:55










  • @Kusalananda probably ongoing stream, not just one line, but it would be nice to know how to do it in both scenarios
    – Alexander Mills
    Apr 20 at 20:57







2




2




Does the Node application produce a single line with a value that you want to capture, or is it a long stream that you don't want to interrupt but you'd like to find a pattern in and use it?
– Kusalananda
Apr 20 at 20:34




Does the Node application produce a single line with a value that you want to capture, or is it a long stream that you don't want to interrupt but you'd like to find a pattern in and use it?
– Kusalananda
Apr 20 at 20:34




2




2




if xxx=$(grep -o 'pattern'); then ...; fi
– jordanm
Apr 20 at 20:55




if xxx=$(grep -o 'pattern'); then ...; fi
– jordanm
Apr 20 at 20:55












@Kusalananda probably ongoing stream, not just one line, but it would be nice to know how to do it in both scenarios
– Alexander Mills
Apr 20 at 20:57




@Kusalananda probably ongoing stream, not just one line, but it would be nice to know how to do it in both scenarios
– Alexander Mills
Apr 20 at 20:57










1 Answer
1






active

oldest

votes

















up vote
1
down vote













I'm assuming your xxx is a stand-in for a pattern of some sort.





delete_lock () 
LOCK="$(grep -m1 -o "lockname:xxx")"
if [ -n "$LOCK#lockname:" ]; then
release_lock "$LOCK#lockname:"
fi


node foo.js | delete_lock


This will stop processing data once it observes the first match for lockname:xxx. It then uses parameter expansion to remove the lockname: prefix and, assuming there was a match (e.g. xxx, runs release_lock on it (e.g. release_lock "xxx").



If you don't want the node call to be cut short, or you want more than one match, remove the -m1 option to grep, though note the quotes may not work with your release_lock code (and be careful about removing those quotes, you don't want to allow rogue characters!).






share|improve this answer





















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f439021%2freference-the-stdin-sent-from-piped-sender-process%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    I'm assuming your xxx is a stand-in for a pattern of some sort.





    delete_lock () 
    LOCK="$(grep -m1 -o "lockname:xxx")"
    if [ -n "$LOCK#lockname:" ]; then
    release_lock "$LOCK#lockname:"
    fi


    node foo.js | delete_lock


    This will stop processing data once it observes the first match for lockname:xxx. It then uses parameter expansion to remove the lockname: prefix and, assuming there was a match (e.g. xxx, runs release_lock on it (e.g. release_lock "xxx").



    If you don't want the node call to be cut short, or you want more than one match, remove the -m1 option to grep, though note the quotes may not work with your release_lock code (and be careful about removing those quotes, you don't want to allow rogue characters!).






    share|improve this answer

























      up vote
      1
      down vote













      I'm assuming your xxx is a stand-in for a pattern of some sort.





      delete_lock () 
      LOCK="$(grep -m1 -o "lockname:xxx")"
      if [ -n "$LOCK#lockname:" ]; then
      release_lock "$LOCK#lockname:"
      fi


      node foo.js | delete_lock


      This will stop processing data once it observes the first match for lockname:xxx. It then uses parameter expansion to remove the lockname: prefix and, assuming there was a match (e.g. xxx, runs release_lock on it (e.g. release_lock "xxx").



      If you don't want the node call to be cut short, or you want more than one match, remove the -m1 option to grep, though note the quotes may not work with your release_lock code (and be careful about removing those quotes, you don't want to allow rogue characters!).






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        I'm assuming your xxx is a stand-in for a pattern of some sort.





        delete_lock () 
        LOCK="$(grep -m1 -o "lockname:xxx")"
        if [ -n "$LOCK#lockname:" ]; then
        release_lock "$LOCK#lockname:"
        fi


        node foo.js | delete_lock


        This will stop processing data once it observes the first match for lockname:xxx. It then uses parameter expansion to remove the lockname: prefix and, assuming there was a match (e.g. xxx, runs release_lock on it (e.g. release_lock "xxx").



        If you don't want the node call to be cut short, or you want more than one match, remove the -m1 option to grep, though note the quotes may not work with your release_lock code (and be careful about removing those quotes, you don't want to allow rogue characters!).






        share|improve this answer













        I'm assuming your xxx is a stand-in for a pattern of some sort.





        delete_lock () 
        LOCK="$(grep -m1 -o "lockname:xxx")"
        if [ -n "$LOCK#lockname:" ]; then
        release_lock "$LOCK#lockname:"
        fi


        node foo.js | delete_lock


        This will stop processing data once it observes the first match for lockname:xxx. It then uses parameter expansion to remove the lockname: prefix and, assuming there was a match (e.g. xxx, runs release_lock on it (e.g. release_lock "xxx").



        If you don't want the node call to be cut short, or you want more than one match, remove the -m1 option to grep, though note the quotes may not work with your release_lock code (and be careful about removing those quotes, you don't want to allow rogue characters!).







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Apr 20 at 22:33









        Adam Katz

        1,922920




        1,922920






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f439021%2freference-the-stdin-sent-from-piped-sender-process%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)