for loop logic porting from bash to csh

The name of the pictureThe name of the pictureThe name of the pictureClash 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)










share|improve this question























  • 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 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










  • Not in text file . I just want to run on terminal.
    – dcds
    10 hours ago














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)










share|improve this question























  • 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 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










  • Not in text file . I just want to run on terminal.
    – dcds
    10 hours ago












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)










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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, 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










  • 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










  • 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











  • 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










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





share|improve this answer










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 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











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%2f474204%2ffor-loop-logic-porting-from-bash-to-csh%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



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





share|improve this answer










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 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















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





share|improve this answer










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 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













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





share|improve this answer










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






share|improve this answer










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.









share|improve this answer



share|improve this answer








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 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

















  • 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
















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


















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)