Set a variable equal to the output of a command containing non-command words
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
add a comment |
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
2
Remove the space afterlookIn=
. 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
add a comment |
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
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
bash arguments
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 afterlookIn=
. 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
add a comment |
2
Remove the space afterlookIn=
. 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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 25 '18 at 1:38
John KugelmanJohn Kugelman
245k54406459
245k54406459
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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