loop over files to pass as arguments to a script
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a script some.sh
that loops over several files;
#!/bin/bash
path_to_destin ="/some/path/"
path_to_raw ="some/other/path"
list = "001 002 003"
for l in $list
do
mkdir $path_to_destin/output_$l
python somescript.py -input $path_to_raw/dir_$l -output $path_to_destin/output_$l/table_$l.txt
done
This script generates three files table_001.q
, table_002.q
and table_003.q
.
After the loop, another script take as input these files,
some_other_script -i table_001.q -i table_002.q -i table_003.q -o all.q
Is there a way to run as many -i table_***
as it is indicated in $list
?
shell-script
add a comment |Â
up vote
0
down vote
favorite
I have a script some.sh
that loops over several files;
#!/bin/bash
path_to_destin ="/some/path/"
path_to_raw ="some/other/path"
list = "001 002 003"
for l in $list
do
mkdir $path_to_destin/output_$l
python somescript.py -input $path_to_raw/dir_$l -output $path_to_destin/output_$l/table_$l.txt
done
This script generates three files table_001.q
, table_002.q
and table_003.q
.
After the loop, another script take as input these files,
some_other_script -i table_001.q -i table_002.q -i table_003.q -o all.q
Is there a way to run as many -i table_***
as it is indicated in $list
?
shell-script
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a script some.sh
that loops over several files;
#!/bin/bash
path_to_destin ="/some/path/"
path_to_raw ="some/other/path"
list = "001 002 003"
for l in $list
do
mkdir $path_to_destin/output_$l
python somescript.py -input $path_to_raw/dir_$l -output $path_to_destin/output_$l/table_$l.txt
done
This script generates three files table_001.q
, table_002.q
and table_003.q
.
After the loop, another script take as input these files,
some_other_script -i table_001.q -i table_002.q -i table_003.q -o all.q
Is there a way to run as many -i table_***
as it is indicated in $list
?
shell-script
I have a script some.sh
that loops over several files;
#!/bin/bash
path_to_destin ="/some/path/"
path_to_raw ="some/other/path"
list = "001 002 003"
for l in $list
do
mkdir $path_to_destin/output_$l
python somescript.py -input $path_to_raw/dir_$l -output $path_to_destin/output_$l/table_$l.txt
done
This script generates three files table_001.q
, table_002.q
and table_003.q
.
After the loop, another script take as input these files,
some_other_script -i table_001.q -i table_002.q -i table_003.q -o all.q
Is there a way to run as many -i table_***
as it is indicated in $list
?
shell-script
edited May 9 at 14:26
ilkkachu
48.1k669133
48.1k669133
asked May 9 at 13:59
user3037937
83
83
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
#!/bin/bash
indir='/some/other/path'
outdir='/some/path'
list=( 001 002 003 )
for i in "$list[@]"; do
mkdir -p "$outdir/output_$i"
python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"
inargs+=( -i "table_$i.q" )
done
some_other_script "$inargs[@]" -o all.q
Observations:
- Assignments may not have space around
=
. - Indentation and whitespace improves readability.
- Don't loop over strings, loop over arrays.
- Quote all variable expansions.
Regarding quoting of variable expansions:
- Security implications of forgetting to quote a variable in bash/POSIX shells
- Why does my shell script choke on whitespace or other special characters?
Thank you for your input and the solution, really helpful!
â user3037937
May 9 at 15:56
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
#!/bin/bash
indir='/some/other/path'
outdir='/some/path'
list=( 001 002 003 )
for i in "$list[@]"; do
mkdir -p "$outdir/output_$i"
python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"
inargs+=( -i "table_$i.q" )
done
some_other_script "$inargs[@]" -o all.q
Observations:
- Assignments may not have space around
=
. - Indentation and whitespace improves readability.
- Don't loop over strings, loop over arrays.
- Quote all variable expansions.
Regarding quoting of variable expansions:
- Security implications of forgetting to quote a variable in bash/POSIX shells
- Why does my shell script choke on whitespace or other special characters?
Thank you for your input and the solution, really helpful!
â user3037937
May 9 at 15:56
add a comment |Â
up vote
2
down vote
accepted
#!/bin/bash
indir='/some/other/path'
outdir='/some/path'
list=( 001 002 003 )
for i in "$list[@]"; do
mkdir -p "$outdir/output_$i"
python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"
inargs+=( -i "table_$i.q" )
done
some_other_script "$inargs[@]" -o all.q
Observations:
- Assignments may not have space around
=
. - Indentation and whitespace improves readability.
- Don't loop over strings, loop over arrays.
- Quote all variable expansions.
Regarding quoting of variable expansions:
- Security implications of forgetting to quote a variable in bash/POSIX shells
- Why does my shell script choke on whitespace or other special characters?
Thank you for your input and the solution, really helpful!
â user3037937
May 9 at 15:56
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
#!/bin/bash
indir='/some/other/path'
outdir='/some/path'
list=( 001 002 003 )
for i in "$list[@]"; do
mkdir -p "$outdir/output_$i"
python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"
inargs+=( -i "table_$i.q" )
done
some_other_script "$inargs[@]" -o all.q
Observations:
- Assignments may not have space around
=
. - Indentation and whitespace improves readability.
- Don't loop over strings, loop over arrays.
- Quote all variable expansions.
Regarding quoting of variable expansions:
- Security implications of forgetting to quote a variable in bash/POSIX shells
- Why does my shell script choke on whitespace or other special characters?
#!/bin/bash
indir='/some/other/path'
outdir='/some/path'
list=( 001 002 003 )
for i in "$list[@]"; do
mkdir -p "$outdir/output_$i"
python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"
inargs+=( -i "table_$i.q" )
done
some_other_script "$inargs[@]" -o all.q
Observations:
- Assignments may not have space around
=
. - Indentation and whitespace improves readability.
- Don't loop over strings, loop over arrays.
- Quote all variable expansions.
Regarding quoting of variable expansions:
- Security implications of forgetting to quote a variable in bash/POSIX shells
- Why does my shell script choke on whitespace or other special characters?
answered May 9 at 14:12
Kusalananda
102k13199315
102k13199315
Thank you for your input and the solution, really helpful!
â user3037937
May 9 at 15:56
add a comment |Â
Thank you for your input and the solution, really helpful!
â user3037937
May 9 at 15:56
Thank you for your input and the solution, really helpful!
â user3037937
May 9 at 15:56
Thank you for your input and the solution, really helpful!
â user3037937
May 9 at 15:56
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%2f442778%2floop-over-files-to-pass-as-arguments-to-a-script%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