Bash - How to put an array inside values of variable?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a web.txt file which contains:
youtube
facebook
google
My sh file contains:
readarray web < web.txt
url = www.website.com
Commands I have used:
readarray web < web.txt
url = www."$web".com
ping url
Expected output:
ping youtube.com
ping facebook.com
ping google.com
What should be the right syntax? Thanks!
shell variable array
New contributor
add a comment |
up vote
0
down vote
favorite
I have a web.txt file which contains:
youtube
facebook
google
My sh file contains:
readarray web < web.txt
url = www.website.com
Commands I have used:
readarray web < web.txt
url = www."$web".com
ping url
Expected output:
ping youtube.com
ping facebook.com
ping google.com
What should be the right syntax? Thanks!
shell variable array
New contributor
mywiki.wooledge.org/BashFAQ/001
– jasonwryan
3 hours ago
your problem has nothing to do with arrays ..... the problem is withbash parameter substitution
– jsotola
3 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a web.txt file which contains:
youtube
facebook
google
My sh file contains:
readarray web < web.txt
url = www.website.com
Commands I have used:
readarray web < web.txt
url = www."$web".com
ping url
Expected output:
ping youtube.com
ping facebook.com
ping google.com
What should be the right syntax? Thanks!
shell variable array
New contributor
I have a web.txt file which contains:
youtube
facebook
google
My sh file contains:
readarray web < web.txt
url = www.website.com
Commands I have used:
readarray web < web.txt
url = www."$web".com
ping url
Expected output:
ping youtube.com
ping facebook.com
ping google.com
What should be the right syntax? Thanks!
shell variable array
shell variable array
New contributor
New contributor
edited 3 hours ago
steeldriver
33.4k34982
33.4k34982
New contributor
asked 3 hours ago
Ben
1
1
New contributor
New contributor
mywiki.wooledge.org/BashFAQ/001
– jasonwryan
3 hours ago
your problem has nothing to do with arrays ..... the problem is withbash parameter substitution
– jsotola
3 hours ago
add a comment |
mywiki.wooledge.org/BashFAQ/001
– jasonwryan
3 hours ago
your problem has nothing to do with arrays ..... the problem is withbash parameter substitution
– jsotola
3 hours ago
mywiki.wooledge.org/BashFAQ/001
– jasonwryan
3 hours ago
mywiki.wooledge.org/BashFAQ/001
– jasonwryan
3 hours ago
your problem has nothing to do with arrays ..... the problem is with
bash parameter substitution
– jsotola
3 hours ago
your problem has nothing to do with arrays ..... the problem is with
bash parameter substitution
– jsotola
3 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
If you really want to print the expected output shown, then
$ readarray -t web < web.txt
$ printf 'ping www.%s.comn' "$web[@]"
ping www.youtube.com
ping www.facebook.com
ping www.google.com
However if you want to actually ping the hosts, the probably xargs
is simpler e.g.
xargs -a web.txt -I ping -c1 "www..com"
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
If you really want to print the expected output shown, then
$ readarray -t web < web.txt
$ printf 'ping www.%s.comn' "$web[@]"
ping www.youtube.com
ping www.facebook.com
ping www.google.com
However if you want to actually ping the hosts, the probably xargs
is simpler e.g.
xargs -a web.txt -I ping -c1 "www..com"
add a comment |
up vote
3
down vote
If you really want to print the expected output shown, then
$ readarray -t web < web.txt
$ printf 'ping www.%s.comn' "$web[@]"
ping www.youtube.com
ping www.facebook.com
ping www.google.com
However if you want to actually ping the hosts, the probably xargs
is simpler e.g.
xargs -a web.txt -I ping -c1 "www..com"
add a comment |
up vote
3
down vote
up vote
3
down vote
If you really want to print the expected output shown, then
$ readarray -t web < web.txt
$ printf 'ping www.%s.comn' "$web[@]"
ping www.youtube.com
ping www.facebook.com
ping www.google.com
However if you want to actually ping the hosts, the probably xargs
is simpler e.g.
xargs -a web.txt -I ping -c1 "www..com"
If you really want to print the expected output shown, then
$ readarray -t web < web.txt
$ printf 'ping www.%s.comn' "$web[@]"
ping www.youtube.com
ping www.facebook.com
ping www.google.com
However if you want to actually ping the hosts, the probably xargs
is simpler e.g.
xargs -a web.txt -I ping -c1 "www..com"
answered 3 hours ago
steeldriver
33.4k34982
33.4k34982
add a comment |
add a comment |
Ben is a new contributor. Be nice, and check out our Code of Conduct.
Ben is a new contributor. Be nice, and check out our Code of Conduct.
Ben is a new contributor. Be nice, and check out our Code of Conduct.
Ben 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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480876%2fbash-how-to-put-an-array-inside-values-of-variable%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
mywiki.wooledge.org/BashFAQ/001
– jasonwryan
3 hours ago
your problem has nothing to do with arrays ..... the problem is with
bash parameter substitution
– jsotola
3 hours ago