How to pipe multiple results into a command?How to do a control loopHow to make xargs ping and head output as expected?Pipe into if statement?Piping find results into another commandAccessing results of pipe as variable?how to pass multiple commands to sqlite3 in a one liner shell commandhow to pipe PID of java app into a command?How to concatenate results of multiple commands and pipe into another without intermediate file?How to access further members of an array when using bash variable indirection?Pipe echo of associative array into dmenu

Multi tool use
Multi tool use

How to write a vulnerable moment without it seeming cliche or mushy?

Humans meet a distant alien species. How do they standardize? - Units of Measure

Modern approach to radio buttons

Scala list with same adjacent values

Relativistic resistance transformation

What does it mean by "d-ism of Leibniz" and "dotage of Newton" in simple English?

Future enhancements for the finite element method

What if you don't bring your credit card or debit for incidentals?

Is the capacitor drawn or wired wrongly?

Creating Fictional Slavic Place Names

How do I truncate a csv file?

Explain Ant-Man's "not it" scene from Avengers: Endgame

Is there a way to save this session?

How can I offer a test ride while selling a bike?

How do I get a list of only the files (not the directories) from a package?

What should I do about a religious player who refuses to accept the existence of multiple gods in D&D?

Can an old DSLR be upgraded to match modern smartphone image quality

Is the world in Game of Thrones spherical or flat?

Why don't I have ground wiring on any of my outlets?

The most awesome army: 80 men left and 81 returned. Is it true?

How can I grammatically understand "Wir über uns"?

Constructing a CCY Gate

How did the Zip Chip and RocketChip accelerators work for the Apple II?

Bringing Food from Hometown for Out-of-Town Interview?



How to pipe multiple results into a command?


How to do a control loopHow to make xargs ping and head output as expected?Pipe into if statement?Piping find results into another commandAccessing results of pipe as variable?how to pass multiple commands to sqlite3 in a one liner shell commandhow to pipe PID of java app into a command?How to concatenate results of multiple commands and pipe into another without intermediate file?How to access further members of an array when using bash variable indirection?Pipe echo of associative array into dmenu






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








5















I have a piece of code which works, something like this (note this is inside CloudFormation Template for AWS auto deployment):



EFS_SERVER_IPS_ARRAY=( $(aws efs describe-mount-targets --file-system-id $SharedFileSystem | jq '.MountTargets[].IpAddress' -r) )
echo "IPs in EFS_SERVER_IPS_ARRAY:"
for element in "$EFS_SERVER_IPS_ARRAY[@]"
do
echo "$element"
echo "$element $MOUNT_SOURCE" >> /etc/hosts
done


This works but looks ugly. I want to avoid the array variable and the for loop (basically I don't care about the first echo command).



Can I somehow use the output ($element, which is 1 or more, currently 2 lines of IPs) and funnel it into two executions of something like:



long AWS command >> echo $element $MOUNT_SOURCE >> /etc/hosts


with echo executing as many times as there are variables in the array, in current implementation? How would I rewrite this?



The output of the AWS command is like this:



10.10.10.10
10.22.22.22


Then, the added lines in /etc/hosts look like:



10.10.10.10 unique-id.efs.us-east-1.amazonaws.com
10.22.22.22 unique-id.efs.us-east-1.amazonaws.com









share|improve this question
























  • @Jesse_b I edited, added sample output of the aws command. efs host needs two columns: the IP outputted, and the hostname in $MOUNT_SOURCE variable defined outside the snipped I added)

    – Carmageddon
    May 16 at 20:18











  • Yes but is this really adding the IP address to your /etc/hosts? It seems more likely it is just adding the literal numbers 0 and 1 to it.

    – Jesse_b
    May 16 at 20:19











  • @Jesse_b yes it works, already tested on AWS deployment. Why do you think it should output just 0 and 1?

    – Carmageddon
    May 16 at 20:21











  • @Jesse_b, Are you suggesting that potentially, if there'd be only one IP returned (single availability zone), it wont be an array anymore, and break the code? Currently as you see in the snippet, I have @ sign, I have array assignment =(..), so I am not sure if I get your point?

    – Carmageddon
    May 16 at 20:25






  • 1





    No I'm saying that when an array is called with the $!name[@] syntax it will expand to a list of the indices (0 1 2 3, etc) and not the elements (ip1 ip2 ip3, etc).

    – Jesse_b
    May 16 at 20:26


















5















I have a piece of code which works, something like this (note this is inside CloudFormation Template for AWS auto deployment):



EFS_SERVER_IPS_ARRAY=( $(aws efs describe-mount-targets --file-system-id $SharedFileSystem | jq '.MountTargets[].IpAddress' -r) )
echo "IPs in EFS_SERVER_IPS_ARRAY:"
for element in "$EFS_SERVER_IPS_ARRAY[@]"
do
echo "$element"
echo "$element $MOUNT_SOURCE" >> /etc/hosts
done


This works but looks ugly. I want to avoid the array variable and the for loop (basically I don't care about the first echo command).



Can I somehow use the output ($element, which is 1 or more, currently 2 lines of IPs) and funnel it into two executions of something like:



long AWS command >> echo $element $MOUNT_SOURCE >> /etc/hosts


with echo executing as many times as there are variables in the array, in current implementation? How would I rewrite this?



The output of the AWS command is like this:



10.10.10.10
10.22.22.22


Then, the added lines in /etc/hosts look like:



10.10.10.10 unique-id.efs.us-east-1.amazonaws.com
10.22.22.22 unique-id.efs.us-east-1.amazonaws.com









share|improve this question
























  • @Jesse_b I edited, added sample output of the aws command. efs host needs two columns: the IP outputted, and the hostname in $MOUNT_SOURCE variable defined outside the snipped I added)

    – Carmageddon
    May 16 at 20:18











  • Yes but is this really adding the IP address to your /etc/hosts? It seems more likely it is just adding the literal numbers 0 and 1 to it.

    – Jesse_b
    May 16 at 20:19











  • @Jesse_b yes it works, already tested on AWS deployment. Why do you think it should output just 0 and 1?

    – Carmageddon
    May 16 at 20:21











  • @Jesse_b, Are you suggesting that potentially, if there'd be only one IP returned (single availability zone), it wont be an array anymore, and break the code? Currently as you see in the snippet, I have @ sign, I have array assignment =(..), so I am not sure if I get your point?

    – Carmageddon
    May 16 at 20:25






  • 1





    No I'm saying that when an array is called with the $!name[@] syntax it will expand to a list of the indices (0 1 2 3, etc) and not the elements (ip1 ip2 ip3, etc).

    – Jesse_b
    May 16 at 20:26














5












5








5








I have a piece of code which works, something like this (note this is inside CloudFormation Template for AWS auto deployment):



EFS_SERVER_IPS_ARRAY=( $(aws efs describe-mount-targets --file-system-id $SharedFileSystem | jq '.MountTargets[].IpAddress' -r) )
echo "IPs in EFS_SERVER_IPS_ARRAY:"
for element in "$EFS_SERVER_IPS_ARRAY[@]"
do
echo "$element"
echo "$element $MOUNT_SOURCE" >> /etc/hosts
done


This works but looks ugly. I want to avoid the array variable and the for loop (basically I don't care about the first echo command).



Can I somehow use the output ($element, which is 1 or more, currently 2 lines of IPs) and funnel it into two executions of something like:



long AWS command >> echo $element $MOUNT_SOURCE >> /etc/hosts


with echo executing as many times as there are variables in the array, in current implementation? How would I rewrite this?



The output of the AWS command is like this:



10.10.10.10
10.22.22.22


Then, the added lines in /etc/hosts look like:



10.10.10.10 unique-id.efs.us-east-1.amazonaws.com
10.22.22.22 unique-id.efs.us-east-1.amazonaws.com









share|improve this question
















I have a piece of code which works, something like this (note this is inside CloudFormation Template for AWS auto deployment):



EFS_SERVER_IPS_ARRAY=( $(aws efs describe-mount-targets --file-system-id $SharedFileSystem | jq '.MountTargets[].IpAddress' -r) )
echo "IPs in EFS_SERVER_IPS_ARRAY:"
for element in "$EFS_SERVER_IPS_ARRAY[@]"
do
echo "$element"
echo "$element $MOUNT_SOURCE" >> /etc/hosts
done


This works but looks ugly. I want to avoid the array variable and the for loop (basically I don't care about the first echo command).



Can I somehow use the output ($element, which is 1 or more, currently 2 lines of IPs) and funnel it into two executions of something like:



long AWS command >> echo $element $MOUNT_SOURCE >> /etc/hosts


with echo executing as many times as there are variables in the array, in current implementation? How would I rewrite this?



The output of the AWS command is like this:



10.10.10.10
10.22.22.22


Then, the added lines in /etc/hosts look like:



10.10.10.10 unique-id.efs.us-east-1.amazonaws.com
10.22.22.22 unique-id.efs.us-east-1.amazonaws.com






bash shell-script aws bash-expansion bash-array






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 17 at 5:02









jwodder

192111




192111










asked May 16 at 20:08









CarmageddonCarmageddon

1316




1316












  • @Jesse_b I edited, added sample output of the aws command. efs host needs two columns: the IP outputted, and the hostname in $MOUNT_SOURCE variable defined outside the snipped I added)

    – Carmageddon
    May 16 at 20:18











  • Yes but is this really adding the IP address to your /etc/hosts? It seems more likely it is just adding the literal numbers 0 and 1 to it.

    – Jesse_b
    May 16 at 20:19











  • @Jesse_b yes it works, already tested on AWS deployment. Why do you think it should output just 0 and 1?

    – Carmageddon
    May 16 at 20:21











  • @Jesse_b, Are you suggesting that potentially, if there'd be only one IP returned (single availability zone), it wont be an array anymore, and break the code? Currently as you see in the snippet, I have @ sign, I have array assignment =(..), so I am not sure if I get your point?

    – Carmageddon
    May 16 at 20:25






  • 1





    No I'm saying that when an array is called with the $!name[@] syntax it will expand to a list of the indices (0 1 2 3, etc) and not the elements (ip1 ip2 ip3, etc).

    – Jesse_b
    May 16 at 20:26


















  • @Jesse_b I edited, added sample output of the aws command. efs host needs two columns: the IP outputted, and the hostname in $MOUNT_SOURCE variable defined outside the snipped I added)

    – Carmageddon
    May 16 at 20:18











  • Yes but is this really adding the IP address to your /etc/hosts? It seems more likely it is just adding the literal numbers 0 and 1 to it.

    – Jesse_b
    May 16 at 20:19











  • @Jesse_b yes it works, already tested on AWS deployment. Why do you think it should output just 0 and 1?

    – Carmageddon
    May 16 at 20:21











  • @Jesse_b, Are you suggesting that potentially, if there'd be only one IP returned (single availability zone), it wont be an array anymore, and break the code? Currently as you see in the snippet, I have @ sign, I have array assignment =(..), so I am not sure if I get your point?

    – Carmageddon
    May 16 at 20:25






  • 1





    No I'm saying that when an array is called with the $!name[@] syntax it will expand to a list of the indices (0 1 2 3, etc) and not the elements (ip1 ip2 ip3, etc).

    – Jesse_b
    May 16 at 20:26

















@Jesse_b I edited, added sample output of the aws command. efs host needs two columns: the IP outputted, and the hostname in $MOUNT_SOURCE variable defined outside the snipped I added)

– Carmageddon
May 16 at 20:18





@Jesse_b I edited, added sample output of the aws command. efs host needs two columns: the IP outputted, and the hostname in $MOUNT_SOURCE variable defined outside the snipped I added)

– Carmageddon
May 16 at 20:18













Yes but is this really adding the IP address to your /etc/hosts? It seems more likely it is just adding the literal numbers 0 and 1 to it.

– Jesse_b
May 16 at 20:19





Yes but is this really adding the IP address to your /etc/hosts? It seems more likely it is just adding the literal numbers 0 and 1 to it.

– Jesse_b
May 16 at 20:19













@Jesse_b yes it works, already tested on AWS deployment. Why do you think it should output just 0 and 1?

– Carmageddon
May 16 at 20:21





@Jesse_b yes it works, already tested on AWS deployment. Why do you think it should output just 0 and 1?

– Carmageddon
May 16 at 20:21













@Jesse_b, Are you suggesting that potentially, if there'd be only one IP returned (single availability zone), it wont be an array anymore, and break the code? Currently as you see in the snippet, I have @ sign, I have array assignment =(..), so I am not sure if I get your point?

– Carmageddon
May 16 at 20:25





@Jesse_b, Are you suggesting that potentially, if there'd be only one IP returned (single availability zone), it wont be an array anymore, and break the code? Currently as you see in the snippet, I have @ sign, I have array assignment =(..), so I am not sure if I get your point?

– Carmageddon
May 16 at 20:25




1




1





No I'm saying that when an array is called with the $!name[@] syntax it will expand to a list of the indices (0 1 2 3, etc) and not the elements (ip1 ip2 ip3, etc).

– Jesse_b
May 16 at 20:26






No I'm saying that when an array is called with the $!name[@] syntax it will expand to a list of the indices (0 1 2 3, etc) and not the elements (ip1 ip2 ip3, etc).

– Jesse_b
May 16 at 20:26











1 Answer
1






active

oldest

votes


















8














aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq --arg mntsrc "$MOUNT_SOURCE" '.MountTargets[].IpAddress | . + $mntsrc' -r >> /etc/hosts


or, if you prefer,



aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq '.MountTargets[].IpAddress' -r | sed -e "s~$~$MOUNT_SOURCE~" >> /etc/hosts


All that's happening is adding some extra fixed text to the end of each line, which can happen either in jq (top) or in various ways outside (bottom). There's not really any array context here or anything being repeated, so you don't need a loop.






share|improve this answer


















  • 1





    Damn hot! Thanks Michael!! I am a happy puppy now, the first one is great. I didnt know about the --args on jq, neat :)

    – Carmageddon
    May 16 at 20:40











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f519366%2fhow-to-pipe-multiple-results-into-a-command%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









8














aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq --arg mntsrc "$MOUNT_SOURCE" '.MountTargets[].IpAddress | . + $mntsrc' -r >> /etc/hosts


or, if you prefer,



aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq '.MountTargets[].IpAddress' -r | sed -e "s~$~$MOUNT_SOURCE~" >> /etc/hosts


All that's happening is adding some extra fixed text to the end of each line, which can happen either in jq (top) or in various ways outside (bottom). There's not really any array context here or anything being repeated, so you don't need a loop.






share|improve this answer


















  • 1





    Damn hot! Thanks Michael!! I am a happy puppy now, the first one is great. I didnt know about the --args on jq, neat :)

    – Carmageddon
    May 16 at 20:40















8














aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq --arg mntsrc "$MOUNT_SOURCE" '.MountTargets[].IpAddress | . + $mntsrc' -r >> /etc/hosts


or, if you prefer,



aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq '.MountTargets[].IpAddress' -r | sed -e "s~$~$MOUNT_SOURCE~" >> /etc/hosts


All that's happening is adding some extra fixed text to the end of each line, which can happen either in jq (top) or in various ways outside (bottom). There's not really any array context here or anything being repeated, so you don't need a loop.






share|improve this answer


















  • 1





    Damn hot! Thanks Michael!! I am a happy puppy now, the first one is great. I didnt know about the --args on jq, neat :)

    – Carmageddon
    May 16 at 20:40













8












8








8







aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq --arg mntsrc "$MOUNT_SOURCE" '.MountTargets[].IpAddress | . + $mntsrc' -r >> /etc/hosts


or, if you prefer,



aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq '.MountTargets[].IpAddress' -r | sed -e "s~$~$MOUNT_SOURCE~" >> /etc/hosts


All that's happening is adding some extra fixed text to the end of each line, which can happen either in jq (top) or in various ways outside (bottom). There's not really any array context here or anything being repeated, so you don't need a loop.






share|improve this answer













aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq --arg mntsrc "$MOUNT_SOURCE" '.MountTargets[].IpAddress | . + $mntsrc' -r >> /etc/hosts


or, if you prefer,



aws efs describe-mount-targets --file-system-id $SharedFileSystem 
| jq '.MountTargets[].IpAddress' -r | sed -e "s~$~$MOUNT_SOURCE~" >> /etc/hosts


All that's happening is adding some extra fixed text to the end of each line, which can happen either in jq (top) or in various ways outside (bottom). There's not really any array context here or anything being repeated, so you don't need a loop.







share|improve this answer












share|improve this answer



share|improve this answer










answered May 16 at 20:34









Michael HomerMichael Homer

52.6k9146182




52.6k9146182







  • 1





    Damn hot! Thanks Michael!! I am a happy puppy now, the first one is great. I didnt know about the --args on jq, neat :)

    – Carmageddon
    May 16 at 20:40












  • 1





    Damn hot! Thanks Michael!! I am a happy puppy now, the first one is great. I didnt know about the --args on jq, neat :)

    – Carmageddon
    May 16 at 20:40







1




1





Damn hot! Thanks Michael!! I am a happy puppy now, the first one is great. I didnt know about the --args on jq, neat :)

– Carmageddon
May 16 at 20:40





Damn hot! Thanks Michael!! I am a happy puppy now, the first one is great. I didnt know about the --args on jq, neat :)

– Carmageddon
May 16 at 20:40

















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f519366%2fhow-to-pipe-multiple-results-into-a-command%23new-answer', 'question_page');

);

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







nbGF,yjfu pQkv,csPm,Vyknd XetRWYZr aqt1kp5a
4M qfUWW0053bp3wuq fTUYee4zgQuSyXV8 kt,UJqU,qpkO0tNN

Popular posts from this blog

RemoteApp sporadic failureWindows 2008 RemoteAPP client disconnects within a matter of minutesWhat is the minimum version of RDP supported by Server 2012 RDS?How to configure a Remoteapp server to increase stabilityMicrosoft RemoteApp Active SessionRDWeb TS connection broken for some users post RemoteApp certificate changeRemote Desktop Licensing, RemoteAPPRDS 2012 R2 some users are not able to logon after changed date and time on Connection BrokersWhat happens during Remote Desktop logon, and is there any logging?After installing RDS on WinServer 2016 I still can only connect with two users?RD Connection via RDGW to Session host is not connecting

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020