for loop logic porting from bash to csh

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have below code snippet working in bash:
for i in `ps -eaf | grep -i <pattern> | awk 'print $3'`; do kill -9 $i; done
But I have a requirement to port this code to work in csh shell due to some legacy application is written using csh.
Sample output of "ps -eaf | grep -i | awk 'print $3'"
5284
3543
14390
4811
4814
I am on RHEL 7.2 (tcsh-6.18.01-8.el7.x86_64, bash-4.2.46-19.el7.x86_64)
linux bash for csh
 |Â
show 1 more comment
up vote
1
down vote
favorite
I have below code snippet working in bash:
for i in `ps -eaf | grep -i <pattern> | awk 'print $3'`; do kill -9 $i; done
But I have a requirement to port this code to work in csh shell due to some legacy application is written using csh.
Sample output of "ps -eaf | grep -i | awk 'print $3'"
5284
3543
14390
4811
4814
I am on RHEL 7.2 (tcsh-6.18.01-8.el7.x86_64, bash-4.2.46-19.el7.x86_64)
linux bash for csh
Hello, @dcds, you would like to get integer number frim where? Variable? Read it from a file?
â Goro
11 hours ago
Hi @Goro I will be getting process Ids by using some grep patterns.
â dcds
11 hours ago
would you please include example? this will be very helpful and our answer will be more accurate, aftergrepare these ids saved in a file or just variables
â Goro
11 hours ago
Hi @Goro I have updated the question.
â dcds
10 hours ago
Not in text file . I just want to run on terminal.
â dcds
10 hours ago
 |Â
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have below code snippet working in bash:
for i in `ps -eaf | grep -i <pattern> | awk 'print $3'`; do kill -9 $i; done
But I have a requirement to port this code to work in csh shell due to some legacy application is written using csh.
Sample output of "ps -eaf | grep -i | awk 'print $3'"
5284
3543
14390
4811
4814
I am on RHEL 7.2 (tcsh-6.18.01-8.el7.x86_64, bash-4.2.46-19.el7.x86_64)
linux bash for csh
I have below code snippet working in bash:
for i in `ps -eaf | grep -i <pattern> | awk 'print $3'`; do kill -9 $i; done
But I have a requirement to port this code to work in csh shell due to some legacy application is written using csh.
Sample output of "ps -eaf | grep -i | awk 'print $3'"
5284
3543
14390
4811
4814
I am on RHEL 7.2 (tcsh-6.18.01-8.el7.x86_64, bash-4.2.46-19.el7.x86_64)
linux bash for csh
linux bash for csh
edited 7 hours ago
Rui F Ribeiro
37k1273117
37k1273117
asked 12 hours ago
dcds
1102415
1102415
Hello, @dcds, you would like to get integer number frim where? Variable? Read it from a file?
â Goro
11 hours ago
Hi @Goro I will be getting process Ids by using some grep patterns.
â dcds
11 hours ago
would you please include example? this will be very helpful and our answer will be more accurate, aftergrepare these ids saved in a file or just variables
â Goro
11 hours ago
Hi @Goro I have updated the question.
â dcds
10 hours ago
Not in text file . I just want to run on terminal.
â dcds
10 hours ago
 |Â
show 1 more comment
Hello, @dcds, you would like to get integer number frim where? Variable? Read it from a file?
â Goro
11 hours ago
Hi @Goro I will be getting process Ids by using some grep patterns.
â dcds
11 hours ago
would you please include example? this will be very helpful and our answer will be more accurate, aftergrepare these ids saved in a file or just variables
â Goro
11 hours ago
Hi @Goro I have updated the question.
â dcds
10 hours ago
Not in text file . I just want to run on terminal.
â dcds
10 hours ago
Hello, @dcds, you would like to get integer number frim where? Variable? Read it from a file?
â Goro
11 hours ago
Hello, @dcds, you would like to get integer number frim where? Variable? Read it from a file?
â Goro
11 hours ago
Hi @Goro I will be getting process Ids by using some grep patterns.
â dcds
11 hours ago
Hi @Goro I will be getting process Ids by using some grep patterns.
â dcds
11 hours ago
would you please include example? this will be very helpful and our answer will be more accurate, after
grep are these ids saved in a file or just variablesâ Goro
11 hours ago
would you please include example? this will be very helpful and our answer will be more accurate, after
grep are these ids saved in a file or just variablesâ Goro
11 hours ago
Hi @Goro I have updated the question.
â dcds
10 hours ago
Hi @Goro I have updated the question.
â dcds
10 hours ago
Not in text file . I just want to run on terminal.
â dcds
10 hours ago
Not in text file . I just want to run on terminal.
â dcds
10 hours ago
 |Â
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
foreach i (`echo 1 2 3`)
echo $i
end
Using your example:
foreach i (`ps -eaf | grep -i <pattern> | awk 'print $3'`)
kill -9 $i
end
New contributor
qubert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to run this in single line in terminal.
â dcds
10 hours ago
the run it withxargs, as the other answer suggested:ps -eaf | grep -i <pattern> | awk 'print $3' | xargs kill -9.foreach ... endcannot be on a single line incsh.
â qubert
10 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
foreach i (`echo 1 2 3`)
echo $i
end
Using your example:
foreach i (`ps -eaf | grep -i <pattern> | awk 'print $3'`)
kill -9 $i
end
New contributor
qubert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to run this in single line in terminal.
â dcds
10 hours ago
the run it withxargs, as the other answer suggested:ps -eaf | grep -i <pattern> | awk 'print $3' | xargs kill -9.foreach ... endcannot be on a single line incsh.
â qubert
10 hours ago
add a comment |Â
up vote
1
down vote
accepted
foreach i (`echo 1 2 3`)
echo $i
end
Using your example:
foreach i (`ps -eaf | grep -i <pattern> | awk 'print $3'`)
kill -9 $i
end
New contributor
qubert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to run this in single line in terminal.
â dcds
10 hours ago
the run it withxargs, as the other answer suggested:ps -eaf | grep -i <pattern> | awk 'print $3' | xargs kill -9.foreach ... endcannot be on a single line incsh.
â qubert
10 hours ago
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
foreach i (`echo 1 2 3`)
echo $i
end
Using your example:
foreach i (`ps -eaf | grep -i <pattern> | awk 'print $3'`)
kill -9 $i
end
New contributor
qubert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
foreach i (`echo 1 2 3`)
echo $i
end
Using your example:
foreach i (`ps -eaf | grep -i <pattern> | awk 'print $3'`)
kill -9 $i
end
New contributor
qubert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 10 hours ago
New contributor
qubert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 12 hours ago
qubert
513
513
New contributor
qubert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
qubert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
qubert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to run this in single line in terminal.
â dcds
10 hours ago
the run it withxargs, as the other answer suggested:ps -eaf | grep -i <pattern> | awk 'print $3' | xargs kill -9.foreach ... endcannot be on a single line incsh.
â qubert
10 hours ago
add a comment |Â
I want to run this in single line in terminal.
â dcds
10 hours ago
the run it withxargs, as the other answer suggested:ps -eaf | grep -i <pattern> | awk 'print $3' | xargs kill -9.foreach ... endcannot be on a single line incsh.
â qubert
10 hours ago
I want to run this in single line in terminal.
â dcds
10 hours ago
I want to run this in single line in terminal.
â dcds
10 hours ago
the run it with
xargs, as the other answer suggested: ps -eaf | grep -i <pattern> | awk 'print $3' | xargs kill -9. foreach ... end cannot be on a single line in csh.â qubert
10 hours ago
the run it with
xargs, as the other answer suggested: ps -eaf | grep -i <pattern> | awk 'print $3' | xargs kill -9. foreach ... end cannot be on a single line in csh.â qubert
10 hours ago
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474204%2ffor-loop-logic-porting-from-bash-to-csh%23new-answer', 'question_page');
);
Post as a guest
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
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
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
Hello, @dcds, you would like to get integer number frim where? Variable? Read it from a file?
â Goro
11 hours ago
Hi @Goro I will be getting process Ids by using some grep patterns.
â dcds
11 hours ago
would you please include example? this will be very helpful and our answer will be more accurate, after
grepare these ids saved in a file or just variablesâ Goro
11 hours ago
Hi @Goro I have updated the question.
â dcds
10 hours ago
Not in text file . I just want to run on terminal.
â dcds
10 hours ago