for loop not working in bashParse two files input in for/while loopfor loop to iterate through some file nth positionHow to use 3rd variable in BASH for loop?how can we use multiple variables in single for loop in shell script?Infinite Loop in Nested For Loopwhile loop to check for user input not in for loopBegin for loop every time where it ended lastFor loop not working in a function with arguments
Does a face-down creature with morph retain its damage when it is turned face up?
Science fiction short story where aliens contact a drunk about Earth's impending destruction
Algorithms vs LP or MIP
Can pay be witheld for hours cleaning up after closing time?
for loop not working in bash
How should I face my manager if I make a mistake because a senior coworker explained something incorrectly to me?
Can realistic planetary invasion have any meaningful strategy?
Are illustrations in novels frowned upon?
Why is my Earth simulation slower than the reality?
Why does The Ancient One think differently about Doctor Strange in Endgame than the film Doctor Strange?
Earth rotation discrepancy
I have a player who yells
Are there account age or level requirements for obtaining special research?
Numbers Decrease while Letters Increase
Irish Snap: Variant Rules
Does norwegian.no airline overbook flights?
Is using a hyperlink to close a modal a poor design decision?
Cross-referencing enumerate item
What is wrong about this application of Kirchhoffs Current Law?
Does acid dissolve PETG 3D prints?
Dealing with an extrovert co-worker
Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")
Compelling story with the world as a villain
Avoiding racist tropes in fantasy
for loop not working in bash
Parse two files input in for/while loopfor loop to iterate through some file nth positionHow to use 3rd variable in BASH for loop?how can we use multiple variables in single for loop in shell script?Infinite Loop in Nested For Loopwhile loop to check for user input not in for loopBegin for loop every time where it ended lastFor loop not working in a function with arguments
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
i have the below code to replace some strigns in multiple files, but the for loop is checking for the first file and not executing the perl script. below is my code
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in $(./zebu.work.post_opt/ZEBU_CTO_FT_MOD*);
do
perl -i -p -e 's/input/inout/g' $file;
perl -i -p -e 's/output/inout/g' $file;
perl -i -p -e 's/wire.*n/tran(i0, o);/g' $file;
perl -i -p -e 's/assign.*n//g' $file;
done
fi
bash for
New contributor
add a comment |
i have the below code to replace some strigns in multiple files, but the for loop is checking for the first file and not executing the perl script. below is my code
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in $(./zebu.work.post_opt/ZEBU_CTO_FT_MOD*);
do
perl -i -p -e 's/input/inout/g' $file;
perl -i -p -e 's/output/inout/g' $file;
perl -i -p -e 's/wire.*n/tran(i0, o);/g' $file;
perl -i -p -e 's/assign.*n//g' $file;
done
fi
bash for
New contributor
1
Remove the$(...)
around your filename globbing pattern. You don't need a command substitution there. You may also combine the four Perl invocations to a single one for speed.
– Kusalananda♦
8 hours ago
add a comment |
i have the below code to replace some strigns in multiple files, but the for loop is checking for the first file and not executing the perl script. below is my code
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in $(./zebu.work.post_opt/ZEBU_CTO_FT_MOD*);
do
perl -i -p -e 's/input/inout/g' $file;
perl -i -p -e 's/output/inout/g' $file;
perl -i -p -e 's/wire.*n/tran(i0, o);/g' $file;
perl -i -p -e 's/assign.*n//g' $file;
done
fi
bash for
New contributor
i have the below code to replace some strigns in multiple files, but the for loop is checking for the first file and not executing the perl script. below is my code
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in $(./zebu.work.post_opt/ZEBU_CTO_FT_MOD*);
do
perl -i -p -e 's/input/inout/g' $file;
perl -i -p -e 's/output/inout/g' $file;
perl -i -p -e 's/wire.*n/tran(i0, o);/g' $file;
perl -i -p -e 's/assign.*n//g' $file;
done
fi
bash for
bash for
New contributor
New contributor
edited 8 hours ago
pLumo
7,45814 silver badges33 bronze badges
7,45814 silver badges33 bronze badges
New contributor
asked 8 hours ago
sudhir prabhusudhir prabhu
211 bronze badge
211 bronze badge
New contributor
New contributor
1
Remove the$(...)
around your filename globbing pattern. You don't need a command substitution there. You may also combine the four Perl invocations to a single one for speed.
– Kusalananda♦
8 hours ago
add a comment |
1
Remove the$(...)
around your filename globbing pattern. You don't need a command substitution there. You may also combine the four Perl invocations to a single one for speed.
– Kusalananda♦
8 hours ago
1
1
Remove the
$(...)
around your filename globbing pattern. You don't need a command substitution there. You may also combine the four Perl invocations to a single one for speed.– Kusalananda♦
8 hours ago
Remove the
$(...)
around your filename globbing pattern. You don't need a command substitution there. You may also combine the four Perl invocations to a single one for speed.– Kusalananda♦
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
The $(foo)
construct will run the command foo
and replace $(foo)
with the output of running foo
. You want a glob, that's not a command. What you're doing is attempting to run all files called ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
. All you need is:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g' "$file"
perl -i -p -e 's/output/inout/g' "$file"
perl -i -p -e 's/wire.*n/tran(i0, o);/g' "$file"
perl -i -p -e 's/assign.*n//g' "$file"
done
fi
Or, more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' "$file"
done
fi
Or even more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
fi
1
Is the loop even needed? Canperl -ip
work on several files at once? I've never tested taht.
– Kusalananda♦
8 hours ago
@Kusalananda indeed it can. Should have thought of that, thanks!
– terdon♦
8 hours ago
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
);
);
sudhir prabhu is a new contributor. Be nice, and check out our Code of Conduct.
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%2f536882%2ffor-loop-not-working-in-bash%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
The $(foo)
construct will run the command foo
and replace $(foo)
with the output of running foo
. You want a glob, that's not a command. What you're doing is attempting to run all files called ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
. All you need is:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g' "$file"
perl -i -p -e 's/output/inout/g' "$file"
perl -i -p -e 's/wire.*n/tran(i0, o);/g' "$file"
perl -i -p -e 's/assign.*n//g' "$file"
done
fi
Or, more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' "$file"
done
fi
Or even more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
fi
1
Is the loop even needed? Canperl -ip
work on several files at once? I've never tested taht.
– Kusalananda♦
8 hours ago
@Kusalananda indeed it can. Should have thought of that, thanks!
– terdon♦
8 hours ago
add a comment |
The $(foo)
construct will run the command foo
and replace $(foo)
with the output of running foo
. You want a glob, that's not a command. What you're doing is attempting to run all files called ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
. All you need is:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g' "$file"
perl -i -p -e 's/output/inout/g' "$file"
perl -i -p -e 's/wire.*n/tran(i0, o);/g' "$file"
perl -i -p -e 's/assign.*n//g' "$file"
done
fi
Or, more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' "$file"
done
fi
Or even more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
fi
1
Is the loop even needed? Canperl -ip
work on several files at once? I've never tested taht.
– Kusalananda♦
8 hours ago
@Kusalananda indeed it can. Should have thought of that, thanks!
– terdon♦
8 hours ago
add a comment |
The $(foo)
construct will run the command foo
and replace $(foo)
with the output of running foo
. You want a glob, that's not a command. What you're doing is attempting to run all files called ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
. All you need is:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g' "$file"
perl -i -p -e 's/output/inout/g' "$file"
perl -i -p -e 's/wire.*n/tran(i0, o);/g' "$file"
perl -i -p -e 's/assign.*n//g' "$file"
done
fi
Or, more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' "$file"
done
fi
Or even more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
fi
The $(foo)
construct will run the command foo
and replace $(foo)
with the output of running foo
. You want a glob, that's not a command. What you're doing is attempting to run all files called ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
. All you need is:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g' "$file"
perl -i -p -e 's/output/inout/g' "$file"
perl -i -p -e 's/wire.*n/tran(i0, o);/g' "$file"
perl -i -p -e 's/assign.*n//g' "$file"
done
fi
Or, more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
for file in ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*;
do
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' "$file"
done
fi
Or even more simply:
if [ -f zebu.work.post_opt/ZEBU_CTO_FT_MOD.v ]
then
perl -i -p -e 's/input/inout/g; s/output/inout/g;
s/wire.*n/tran(i0, o);/g;
s/assign.*n//g' ./zebu.work.post_opt/ZEBU_CTO_FT_MOD*
fi
edited 8 hours ago
Kusalananda♦
160k18 gold badges318 silver badges504 bronze badges
160k18 gold badges318 silver badges504 bronze badges
answered 8 hours ago
terdon♦terdon
141k34 gold badges290 silver badges468 bronze badges
141k34 gold badges290 silver badges468 bronze badges
1
Is the loop even needed? Canperl -ip
work on several files at once? I've never tested taht.
– Kusalananda♦
8 hours ago
@Kusalananda indeed it can. Should have thought of that, thanks!
– terdon♦
8 hours ago
add a comment |
1
Is the loop even needed? Canperl -ip
work on several files at once? I've never tested taht.
– Kusalananda♦
8 hours ago
@Kusalananda indeed it can. Should have thought of that, thanks!
– terdon♦
8 hours ago
1
1
Is the loop even needed? Can
perl -ip
work on several files at once? I've never tested taht.– Kusalananda♦
8 hours ago
Is the loop even needed? Can
perl -ip
work on several files at once? I've never tested taht.– Kusalananda♦
8 hours ago
@Kusalananda indeed it can. Should have thought of that, thanks!
– terdon♦
8 hours ago
@Kusalananda indeed it can. Should have thought of that, thanks!
– terdon♦
8 hours ago
add a comment |
sudhir prabhu is a new contributor. Be nice, and check out our Code of Conduct.
sudhir prabhu is a new contributor. Be nice, and check out our Code of Conduct.
sudhir prabhu is a new contributor. Be nice, and check out our Code of Conduct.
sudhir prabhu is a new contributor. Be nice, and check out our Code of Conduct.
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%2f536882%2ffor-loop-not-working-in-bash%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
Remove the
$(...)
around your filename globbing pattern. You don't need a command substitution there. You may also combine the four Perl invocations to a single one for speed.– Kusalananda♦
8 hours ago