for loop in nohup

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am trying to run bash script which run 8 for loops simulatenously.



one of the my for loop likes below



for i in 00 01 02 03 04 ; do cat $INDIR/sys*$1.$i*csv | awk -F 'xac' 'BEGINOFS=";"; ($4 == 10) $1=$1; print '> $OUTDIR/$1_$i.csv


So I have converted into following syntax to run with nohup



nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv|awk -F '\xac' 'BEGINOFS=";"; ($4==10) $1=$1; print '>$OUTDIR/$i.csv;done' &


But I am getting following error



test.sh: line 9: syntax error near unexpected token `('
test.sh: line 9: `nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv|awk -F '\xac' 'BEGINOFS=";"; ($4==10) $1=$1; print '>$OUTDIR/$i.csv;done' & '


I also tried with following code changes




nohup sh -c ''



nohup /bin/bash -c ''



'xac'




but no progress,



BTW my for loop works without nohup



Thanks for your help







share|improve this question






















  • The root issue here is the single quotes, backslashes don't work inside them, so you have 'for ...|awk -F ' quoted, then the rest is unquoted since the following single-quotes are all escaped.
    – ilkkachu
    Dec 6 '17 at 20:22














up vote
0
down vote

favorite












I am trying to run bash script which run 8 for loops simulatenously.



one of the my for loop likes below



for i in 00 01 02 03 04 ; do cat $INDIR/sys*$1.$i*csv | awk -F 'xac' 'BEGINOFS=";"; ($4 == 10) $1=$1; print '> $OUTDIR/$1_$i.csv


So I have converted into following syntax to run with nohup



nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv|awk -F '\xac' 'BEGINOFS=";"; ($4==10) $1=$1; print '>$OUTDIR/$i.csv;done' &


But I am getting following error



test.sh: line 9: syntax error near unexpected token `('
test.sh: line 9: `nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv|awk -F '\xac' 'BEGINOFS=";"; ($4==10) $1=$1; print '>$OUTDIR/$i.csv;done' & '


I also tried with following code changes




nohup sh -c ''



nohup /bin/bash -c ''



'xac'




but no progress,



BTW my for loop works without nohup



Thanks for your help







share|improve this question






















  • The root issue here is the single quotes, backslashes don't work inside them, so you have 'for ...|awk -F ' quoted, then the rest is unquoted since the following single-quotes are all escaped.
    – ilkkachu
    Dec 6 '17 at 20:22












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to run bash script which run 8 for loops simulatenously.



one of the my for loop likes below



for i in 00 01 02 03 04 ; do cat $INDIR/sys*$1.$i*csv | awk -F 'xac' 'BEGINOFS=";"; ($4 == 10) $1=$1; print '> $OUTDIR/$1_$i.csv


So I have converted into following syntax to run with nohup



nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv|awk -F '\xac' 'BEGINOFS=";"; ($4==10) $1=$1; print '>$OUTDIR/$i.csv;done' &


But I am getting following error



test.sh: line 9: syntax error near unexpected token `('
test.sh: line 9: `nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv|awk -F '\xac' 'BEGINOFS=";"; ($4==10) $1=$1; print '>$OUTDIR/$i.csv;done' & '


I also tried with following code changes




nohup sh -c ''



nohup /bin/bash -c ''



'xac'




but no progress,



BTW my for loop works without nohup



Thanks for your help







share|improve this question














I am trying to run bash script which run 8 for loops simulatenously.



one of the my for loop likes below



for i in 00 01 02 03 04 ; do cat $INDIR/sys*$1.$i*csv | awk -F 'xac' 'BEGINOFS=";"; ($4 == 10) $1=$1; print '> $OUTDIR/$1_$i.csv


So I have converted into following syntax to run with nohup



nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv|awk -F '\xac' 'BEGINOFS=";"; ($4==10) $1=$1; print '>$OUTDIR/$i.csv;done' &


But I am getting following error



test.sh: line 9: syntax error near unexpected token `('
test.sh: line 9: `nohup bash -c 'for i in 00 01 02 03 04; do cat $INDIR/rti*$1.$i*csv|awk -F '\xac' 'BEGINOFS=";"; ($4==10) $1=$1; print '>$OUTDIR/$i.csv;done' & '


I also tried with following code changes




nohup sh -c ''



nohup /bin/bash -c ''



'xac'




but no progress,



BTW my for loop works without nohup



Thanks for your help









share|improve this question













share|improve this question




share|improve this question








edited Dec 6 '17 at 12:53

























asked Dec 6 '17 at 12:48









Murat

256




256











  • The root issue here is the single quotes, backslashes don't work inside them, so you have 'for ...|awk -F ' quoted, then the rest is unquoted since the following single-quotes are all escaped.
    – ilkkachu
    Dec 6 '17 at 20:22
















  • The root issue here is the single quotes, backslashes don't work inside them, so you have 'for ...|awk -F ' quoted, then the rest is unquoted since the following single-quotes are all escaped.
    – ilkkachu
    Dec 6 '17 at 20:22















The root issue here is the single quotes, backslashes don't work inside them, so you have 'for ...|awk -F ' quoted, then the rest is unquoted since the following single-quotes are all escaped.
– ilkkachu
Dec 6 '17 at 20:22




The root issue here is the single quotes, backslashes don't work inside them, so you have 'for ...|awk -F ' quoted, then the rest is unquoted since the following single-quotes are all escaped.
– ilkkachu
Dec 6 '17 at 20:22










1 Answer
1






active

oldest

votes

















up vote
2
down vote













It would be much easier (read: more read- and maintainable) if you divide your code into two scripts: One to execute the actual function(s), and one to start them. Sample code for the latter:



for i in 00 01 02 03 04; do
nohup /path/to/workerScript.sh $i
done


If you want to keep the logic in a single script you can still use this approach:



if [ $# -eq 0 ]; then
for i in 00 01 02 03 04; do
nohup $0 $i
done

exit 0
fi

# Rest of the logic follows





share|improve this answer






















  • Hello Murphy I already have this solution and it works very well. But I am looking one script way :) thanks for your reply
    – Murat
    Dec 8 '17 at 12:49










  • @Murat You can have that and still keep the script readable. I expanded my example.
    – Murphy
    Dec 8 '17 at 13:02











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%2f409199%2ffor-loop-in-nohup%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
2
down vote













It would be much easier (read: more read- and maintainable) if you divide your code into two scripts: One to execute the actual function(s), and one to start them. Sample code for the latter:



for i in 00 01 02 03 04; do
nohup /path/to/workerScript.sh $i
done


If you want to keep the logic in a single script you can still use this approach:



if [ $# -eq 0 ]; then
for i in 00 01 02 03 04; do
nohup $0 $i
done

exit 0
fi

# Rest of the logic follows





share|improve this answer






















  • Hello Murphy I already have this solution and it works very well. But I am looking one script way :) thanks for your reply
    – Murat
    Dec 8 '17 at 12:49










  • @Murat You can have that and still keep the script readable. I expanded my example.
    – Murphy
    Dec 8 '17 at 13:02















up vote
2
down vote













It would be much easier (read: more read- and maintainable) if you divide your code into two scripts: One to execute the actual function(s), and one to start them. Sample code for the latter:



for i in 00 01 02 03 04; do
nohup /path/to/workerScript.sh $i
done


If you want to keep the logic in a single script you can still use this approach:



if [ $# -eq 0 ]; then
for i in 00 01 02 03 04; do
nohup $0 $i
done

exit 0
fi

# Rest of the logic follows





share|improve this answer






















  • Hello Murphy I already have this solution and it works very well. But I am looking one script way :) thanks for your reply
    – Murat
    Dec 8 '17 at 12:49










  • @Murat You can have that and still keep the script readable. I expanded my example.
    – Murphy
    Dec 8 '17 at 13:02













up vote
2
down vote










up vote
2
down vote









It would be much easier (read: more read- and maintainable) if you divide your code into two scripts: One to execute the actual function(s), and one to start them. Sample code for the latter:



for i in 00 01 02 03 04; do
nohup /path/to/workerScript.sh $i
done


If you want to keep the logic in a single script you can still use this approach:



if [ $# -eq 0 ]; then
for i in 00 01 02 03 04; do
nohup $0 $i
done

exit 0
fi

# Rest of the logic follows





share|improve this answer














It would be much easier (read: more read- and maintainable) if you divide your code into two scripts: One to execute the actual function(s), and one to start them. Sample code for the latter:



for i in 00 01 02 03 04; do
nohup /path/to/workerScript.sh $i
done


If you want to keep the logic in a single script you can still use this approach:



if [ $# -eq 0 ]; then
for i in 00 01 02 03 04; do
nohup $0 $i
done

exit 0
fi

# Rest of the logic follows






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 8 '17 at 13:01

























answered Dec 6 '17 at 13:11









Murphy

1,7471517




1,7471517











  • Hello Murphy I already have this solution and it works very well. But I am looking one script way :) thanks for your reply
    – Murat
    Dec 8 '17 at 12:49










  • @Murat You can have that and still keep the script readable. I expanded my example.
    – Murphy
    Dec 8 '17 at 13:02

















  • Hello Murphy I already have this solution and it works very well. But I am looking one script way :) thanks for your reply
    – Murat
    Dec 8 '17 at 12:49










  • @Murat You can have that and still keep the script readable. I expanded my example.
    – Murphy
    Dec 8 '17 at 13:02
















Hello Murphy I already have this solution and it works very well. But I am looking one script way :) thanks for your reply
– Murat
Dec 8 '17 at 12:49




Hello Murphy I already have this solution and it works very well. But I am looking one script way :) thanks for your reply
– Murat
Dec 8 '17 at 12:49












@Murat You can have that and still keep the script readable. I expanded my example.
– Murphy
Dec 8 '17 at 13:02





@Murat You can have that and still keep the script readable. I expanded my example.
– Murphy
Dec 8 '17 at 13:02


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409199%2ffor-loop-in-nohup%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?