Set a variable equal to the output of a command containing non-command words












1















I'm writing a small script in which I want to set the value of a variable equal to the output of a command. However, the command in question is a call to another script with command-line arguments. I'm using backticks as you normally should in this scenario, but the problem is that the the computer gives an error, in which it tries to interpret the command-line arguments as commands.



#!/bin/bash

filename="$1"

while read p; do
echo "This is the gene we are looking at: ""$p"
lookIn= `./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri`
echo "$lookIn"
#grep "$p" "$lookIn""/""prokka_""$lookIn""/*.tsv" | awk '{print $1}'
done < $filename


I'm trying to set variable lookIn equal to the output of ./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri, where ./findGeneIn is a script, and the words burgdorferi,...,parkeri are command line arguments for ./findGeneIn.



The issue, is that I get an error saying "burgdorferi: command not found". So it's trying to interpret those arguments as commands. How do I get it to not do that?










share|improve this question




















  • 2





    Remove the space after lookIn=. Also, use $( ) instead of backticks, and quote the filename (done < "$filename"). shellcheck.net is good at spotting common mistakes like these.

    – Gordon Davisson
    Nov 25 '18 at 1:42
















1















I'm writing a small script in which I want to set the value of a variable equal to the output of a command. However, the command in question is a call to another script with command-line arguments. I'm using backticks as you normally should in this scenario, but the problem is that the the computer gives an error, in which it tries to interpret the command-line arguments as commands.



#!/bin/bash

filename="$1"

while read p; do
echo "This is the gene we are looking at: ""$p"
lookIn= `./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri`
echo "$lookIn"
#grep "$p" "$lookIn""/""prokka_""$lookIn""/*.tsv" | awk '{print $1}'
done < $filename


I'm trying to set variable lookIn equal to the output of ./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri, where ./findGeneIn is a script, and the words burgdorferi,...,parkeri are command line arguments for ./findGeneIn.



The issue, is that I get an error saying "burgdorferi: command not found". So it's trying to interpret those arguments as commands. How do I get it to not do that?










share|improve this question




















  • 2





    Remove the space after lookIn=. Also, use $( ) instead of backticks, and quote the filename (done < "$filename"). shellcheck.net is good at spotting common mistakes like these.

    – Gordon Davisson
    Nov 25 '18 at 1:42














1












1








1


1






I'm writing a small script in which I want to set the value of a variable equal to the output of a command. However, the command in question is a call to another script with command-line arguments. I'm using backticks as you normally should in this scenario, but the problem is that the the computer gives an error, in which it tries to interpret the command-line arguments as commands.



#!/bin/bash

filename="$1"

while read p; do
echo "This is the gene we are looking at: ""$p"
lookIn= `./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri`
echo "$lookIn"
#grep "$p" "$lookIn""/""prokka_""$lookIn""/*.tsv" | awk '{print $1}'
done < $filename


I'm trying to set variable lookIn equal to the output of ./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri, where ./findGeneIn is a script, and the words burgdorferi,...,parkeri are command line arguments for ./findGeneIn.



The issue, is that I get an error saying "burgdorferi: command not found". So it's trying to interpret those arguments as commands. How do I get it to not do that?










share|improve this question
















I'm writing a small script in which I want to set the value of a variable equal to the output of a command. However, the command in question is a call to another script with command-line arguments. I'm using backticks as you normally should in this scenario, but the problem is that the the computer gives an error, in which it tries to interpret the command-line arguments as commands.



#!/bin/bash

filename="$1"

while read p; do
echo "This is the gene we are looking at: ""$p"
lookIn= `./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri`
echo "$lookIn"
#grep "$p" "$lookIn""/""prokka_""$lookIn""/*.tsv" | awk '{print $1}'
done < $filename


I'm trying to set variable lookIn equal to the output of ./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri, where ./findGeneIn is a script, and the words burgdorferi,...,parkeri are command line arguments for ./findGeneIn.



The issue, is that I get an error saying "burgdorferi: command not found". So it's trying to interpret those arguments as commands. How do I get it to not do that?







bash arguments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 1:39









John Kugelman

245k54406459




245k54406459










asked Nov 25 '18 at 1:31









The_QuestionerThe_Questioner

142314




142314








  • 2





    Remove the space after lookIn=. Also, use $( ) instead of backticks, and quote the filename (done < "$filename"). shellcheck.net is good at spotting common mistakes like these.

    – Gordon Davisson
    Nov 25 '18 at 1:42














  • 2





    Remove the space after lookIn=. Also, use $( ) instead of backticks, and quote the filename (done < "$filename"). shellcheck.net is good at spotting common mistakes like these.

    – Gordon Davisson
    Nov 25 '18 at 1:42








2




2





Remove the space after lookIn=. Also, use $( ) instead of backticks, and quote the filename (done < "$filename"). shellcheck.net is good at spotting common mistakes like these.

– Gordon Davisson
Nov 25 '18 at 1:42





Remove the space after lookIn=. Also, use $( ) instead of backticks, and quote the filename (done < "$filename"). shellcheck.net is good at spotting common mistakes like these.

– Gordon Davisson
Nov 25 '18 at 1:42












1 Answer
1






active

oldest

votes


















3














lookIn= `./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri`
^


Delete the extra space. Assignments must not have spaces around the equal sign.



With the space there, Bash parses the line as var=value command, which runs a command with $var temporarily set to "value". Or in this case, it interprets result of the backticks as a command name and lookIn= as an empty variable assignment.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463936%2fset-a-variable-equal-to-the-output-of-a-command-containing-non-command-words%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    lookIn= `./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri`
    ^


    Delete the extra space. Assignments must not have spaces around the equal sign.



    With the space there, Bash parses the line as var=value command, which runs a command with $var temporarily set to "value". Or in this case, it interprets result of the backticks as a command name and lookIn= as an empty variable assignment.






    share|improve this answer




























      3














      lookIn= `./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri`
      ^


      Delete the extra space. Assignments must not have spaces around the equal sign.



      With the space there, Bash parses the line as var=value command, which runs a command with $var temporarily set to "value". Or in this case, it interprets result of the backticks as a command name and lookIn= as an empty variable assignment.






      share|improve this answer


























        3












        3








        3







        lookIn= `./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri`
        ^


        Delete the extra space. Assignments must not have spaces around the equal sign.



        With the space there, Bash parses the line as var=value command, which runs a command with $var temporarily set to "value". Or in this case, it interprets result of the backticks as a command name and lookIn= as an empty variable assignment.






        share|improve this answer













        lookIn= `./findGeneIn "$p" burgdorferi afzelii garinii hermsii miyamotoi parkeri`
        ^


        Delete the extra space. Assignments must not have spaces around the equal sign.



        With the space there, Bash parses the line as var=value command, which runs a command with $var temporarily set to "value". Or in this case, it interprets result of the backticks as a command name and lookIn= as an empty variable assignment.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 1:38









        John KugelmanJohn Kugelman

        245k54406459




        245k54406459
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463936%2fset-a-variable-equal-to-the-output-of-a-command-containing-non-command-words%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen