How do I redirect output to a variable file name in a for loop?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
How do I redirect output to a variable file name in a for loop?
This doesn't work:
for ((j=501; j <=550; j++)); do
curl -x http://us-wa.proxymesh.com:31280 "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000" >trial_$j_out.html 2> trial_$j_error.txt;
done
I keep on having trial_.html and trial_.txt written.
bash shell-script shell
add a comment |Â
up vote
0
down vote
favorite
How do I redirect output to a variable file name in a for loop?
This doesn't work:
for ((j=501; j <=550; j++)); do
curl -x http://us-wa.proxymesh.com:31280 "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000" >trial_$j_out.html 2> trial_$j_error.txt;
done
I keep on having trial_.html and trial_.txt written.
bash shell-script shell
3
Because you have noj_out
orj_error
variable defined. Just replacetrial_$j_out.html
andtrial_$j_error.txt
withtrial_$j_out.html
andtrial_$j_error.txt
.
â user2233709
Oct 21 '17 at 11:26
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How do I redirect output to a variable file name in a for loop?
This doesn't work:
for ((j=501; j <=550; j++)); do
curl -x http://us-wa.proxymesh.com:31280 "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000" >trial_$j_out.html 2> trial_$j_error.txt;
done
I keep on having trial_.html and trial_.txt written.
bash shell-script shell
How do I redirect output to a variable file name in a for loop?
This doesn't work:
for ((j=501; j <=550; j++)); do
curl -x http://us-wa.proxymesh.com:31280 "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000" >trial_$j_out.html 2> trial_$j_error.txt;
done
I keep on having trial_.html and trial_.txt written.
bash shell-script shell
asked Oct 21 '17 at 11:22
humanitiesclinic
3912
3912
3
Because you have noj_out
orj_error
variable defined. Just replacetrial_$j_out.html
andtrial_$j_error.txt
withtrial_$j_out.html
andtrial_$j_error.txt
.
â user2233709
Oct 21 '17 at 11:26
add a comment |Â
3
Because you have noj_out
orj_error
variable defined. Just replacetrial_$j_out.html
andtrial_$j_error.txt
withtrial_$j_out.html
andtrial_$j_error.txt
.
â user2233709
Oct 21 '17 at 11:26
3
3
Because you have no
j_out
or j_error
variable defined. Just replace trial_$j_out.html
and trial_$j_error.txt
with trial_$j_out.html
and trial_$j_error.txt
.â user2233709
Oct 21 '17 at 11:26
Because you have no
j_out
or j_error
variable defined. Just replace trial_$j_out.html
and trial_$j_error.txt
with trial_$j_out.html
and trial_$j_error.txt
.â user2233709
Oct 21 '17 at 11:26
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
As pointed out in comments, _
is a valid character in a variable name. The shell will interpret trial_$j_out.html
and trial_$j_error.txt
as consisting of text surrounding the variables $j_out
and $j_error
.
Use $j
instead, just like you (needlessly) did in the actual URL:
for (( j=501; j<=550; j++ )); do
curl -x http://us-wa.proxymesh.com:31280
"https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
>"trial_$j_out.html" 2>"trial_$j_error.txt"
done
This will properly delimit the name of the variable from the following _
. The $j
in the URL does not need curly braces as the character &
is not valid as part of a variable name.
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
As pointed out in comments, _
is a valid character in a variable name. The shell will interpret trial_$j_out.html
and trial_$j_error.txt
as consisting of text surrounding the variables $j_out
and $j_error
.
Use $j
instead, just like you (needlessly) did in the actual URL:
for (( j=501; j<=550; j++ )); do
curl -x http://us-wa.proxymesh.com:31280
"https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
>"trial_$j_out.html" 2>"trial_$j_error.txt"
done
This will properly delimit the name of the variable from the following _
. The $j
in the URL does not need curly braces as the character &
is not valid as part of a variable name.
add a comment |Â
up vote
2
down vote
As pointed out in comments, _
is a valid character in a variable name. The shell will interpret trial_$j_out.html
and trial_$j_error.txt
as consisting of text surrounding the variables $j_out
and $j_error
.
Use $j
instead, just like you (needlessly) did in the actual URL:
for (( j=501; j<=550; j++ )); do
curl -x http://us-wa.proxymesh.com:31280
"https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
>"trial_$j_out.html" 2>"trial_$j_error.txt"
done
This will properly delimit the name of the variable from the following _
. The $j
in the URL does not need curly braces as the character &
is not valid as part of a variable name.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
As pointed out in comments, _
is a valid character in a variable name. The shell will interpret trial_$j_out.html
and trial_$j_error.txt
as consisting of text surrounding the variables $j_out
and $j_error
.
Use $j
instead, just like you (needlessly) did in the actual URL:
for (( j=501; j<=550; j++ )); do
curl -x http://us-wa.proxymesh.com:31280
"https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
>"trial_$j_out.html" 2>"trial_$j_error.txt"
done
This will properly delimit the name of the variable from the following _
. The $j
in the URL does not need curly braces as the character &
is not valid as part of a variable name.
As pointed out in comments, _
is a valid character in a variable name. The shell will interpret trial_$j_out.html
and trial_$j_error.txt
as consisting of text surrounding the variables $j_out
and $j_error
.
Use $j
instead, just like you (needlessly) did in the actual URL:
for (( j=501; j<=550; j++ )); do
curl -x http://us-wa.proxymesh.com:31280
"https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
>"trial_$j_out.html" 2>"trial_$j_error.txt"
done
This will properly delimit the name of the variable from the following _
. The $j
in the URL does not need curly braces as the character &
is not valid as part of a variable name.
answered Oct 21 '17 at 11:59
Kusalananda
105k14209326
105k14209326
add a comment |Â
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%2f399524%2fhow-do-i-redirect-output-to-a-variable-file-name-in-a-for-loop%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
3
Because you have no
j_out
orj_error
variable defined. Just replacetrial_$j_out.html
andtrial_$j_error.txt
withtrial_$j_out.html
andtrial_$j_error.txt
.â user2233709
Oct 21 '17 at 11:26