Bash Command Not Found Error with $variable

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
108 ps --ppid $process | while read -r line ; do
109 #echo $line | awk 'print $1;
110 child=$($line | awk 'print $1;')
111 echo $child
113 done
Running this code gives me the following error:
line 111: 3405: command not found
But if I uncomment line 109 it prints the correct value without an error
bash command-not-found
add a comment |
108 ps --ppid $process | while read -r line ; do
109 #echo $line | awk 'print $1;
110 child=$($line | awk 'print $1;')
111 echo $child
113 done
Running this code gives me the following error:
line 111: 3405: command not found
But if I uncomment line 109 it prints the correct value without an error
bash command-not-found
1
What are you expecting to happen? without theecho$linewill be treated as a command to run, apparently the command3405in your example.
– Eric Renouf
Nov 27 '16 at 1:52
3
This smacks of an XY problem to me, what is it that you're actually trying to do?
– Eric Renouf
Nov 27 '16 at 1:54
1
line 110 looks fishy to me (did you mean to 'echo $line' to awk?)
– Jeff Schaller♦
Nov 27 '16 at 2:00
Post complete code that reproduces the problem and explain what you want the script to do.
– Gilles
Nov 27 '16 at 21:19
add a comment |
108 ps --ppid $process | while read -r line ; do
109 #echo $line | awk 'print $1;
110 child=$($line | awk 'print $1;')
111 echo $child
113 done
Running this code gives me the following error:
line 111: 3405: command not found
But if I uncomment line 109 it prints the correct value without an error
bash command-not-found
108 ps --ppid $process | while read -r line ; do
109 #echo $line | awk 'print $1;
110 child=$($line | awk 'print $1;')
111 echo $child
113 done
Running this code gives me the following error:
line 111: 3405: command not found
But if I uncomment line 109 it prints the correct value without an error
bash command-not-found
bash command-not-found
edited Nov 27 '16 at 1:44
techraf
4,303102243
4,303102243
asked Nov 27 '16 at 1:43
shav017shav017
41
41
1
What are you expecting to happen? without theecho$linewill be treated as a command to run, apparently the command3405in your example.
– Eric Renouf
Nov 27 '16 at 1:52
3
This smacks of an XY problem to me, what is it that you're actually trying to do?
– Eric Renouf
Nov 27 '16 at 1:54
1
line 110 looks fishy to me (did you mean to 'echo $line' to awk?)
– Jeff Schaller♦
Nov 27 '16 at 2:00
Post complete code that reproduces the problem and explain what you want the script to do.
– Gilles
Nov 27 '16 at 21:19
add a comment |
1
What are you expecting to happen? without theecho$linewill be treated as a command to run, apparently the command3405in your example.
– Eric Renouf
Nov 27 '16 at 1:52
3
This smacks of an XY problem to me, what is it that you're actually trying to do?
– Eric Renouf
Nov 27 '16 at 1:54
1
line 110 looks fishy to me (did you mean to 'echo $line' to awk?)
– Jeff Schaller♦
Nov 27 '16 at 2:00
Post complete code that reproduces the problem and explain what you want the script to do.
– Gilles
Nov 27 '16 at 21:19
1
1
What are you expecting to happen? without the
echo $line will be treated as a command to run, apparently the command 3405 in your example.– Eric Renouf
Nov 27 '16 at 1:52
What are you expecting to happen? without the
echo $line will be treated as a command to run, apparently the command 3405 in your example.– Eric Renouf
Nov 27 '16 at 1:52
3
3
This smacks of an XY problem to me, what is it that you're actually trying to do?
– Eric Renouf
Nov 27 '16 at 1:54
This smacks of an XY problem to me, what is it that you're actually trying to do?
– Eric Renouf
Nov 27 '16 at 1:54
1
1
line 110 looks fishy to me (did you mean to 'echo $line' to awk?)
– Jeff Schaller♦
Nov 27 '16 at 2:00
line 110 looks fishy to me (did you mean to 'echo $line' to awk?)
– Jeff Schaller♦
Nov 27 '16 at 2:00
Post complete code that reproduces the problem and explain what you want the script to do.
– Gilles
Nov 27 '16 at 21:19
Post complete code that reproduces the problem and explain what you want the script to do.
– Gilles
Nov 27 '16 at 21:19
add a comment |
2 Answers
2
active
oldest
votes
Fix it...
ps --ppid $process | while read -r line ; do
child=$(echo $line | awk 'print $1')
done
add a comment |
The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.
If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:
ps --ppid "$process" -o pid=
This would get the list of processes that has $process as their PPID, and for each output their PID.
Also related:
- Why is using a shell loop to process text considered bad practice?
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f326289%2fbash-command-not-found-error-with-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Fix it...
ps --ppid $process | while read -r line ; do
child=$(echo $line | awk 'print $1')
done
add a comment |
Fix it...
ps --ppid $process | while read -r line ; do
child=$(echo $line | awk 'print $1')
done
add a comment |
Fix it...
ps --ppid $process | while read -r line ; do
child=$(echo $line | awk 'print $1')
done
Fix it...
ps --ppid $process | while read -r line ; do
child=$(echo $line | awk 'print $1')
done
answered Nov 27 '16 at 2:00
jas-jas-
73238
73238
add a comment |
add a comment |
The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.
If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:
ps --ppid "$process" -o pid=
This would get the list of processes that has $process as their PPID, and for each output their PID.
Also related:
- Why is using a shell loop to process text considered bad practice?
add a comment |
The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.
If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:
ps --ppid "$process" -o pid=
This would get the list of processes that has $process as their PPID, and for each output their PID.
Also related:
- Why is using a shell loop to process text considered bad practice?
add a comment |
The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.
If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:
ps --ppid "$process" -o pid=
This would get the list of processes that has $process as their PPID, and for each output their PID.
Also related:
- Why is using a shell loop to process text considered bad practice?
The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.
If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:
ps --ppid "$process" -o pid=
This would get the list of processes that has $process as their PPID, and for each output their PID.
Also related:
- Why is using a shell loop to process text considered bad practice?
answered Mar 17 at 14:15
Kusalananda♦Kusalananda
142k18264440
142k18264440
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f326289%2fbash-command-not-found-error-with-variable%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
1
What are you expecting to happen? without the
echo$linewill be treated as a command to run, apparently the command3405in your example.– Eric Renouf
Nov 27 '16 at 1:52
3
This smacks of an XY problem to me, what is it that you're actually trying to do?
– Eric Renouf
Nov 27 '16 at 1:54
1
line 110 looks fishy to me (did you mean to 'echo $line' to awk?)
– Jeff Schaller♦
Nov 27 '16 at 2:00
Post complete code that reproduces the problem and explain what you want the script to do.
– Gilles
Nov 27 '16 at 21:19