How to pipe multiple results into a command?How to do a control loopHow to make xargs ping and head output as...

How do you cope with rejection?

Error when running ((x++)) as root

What technology would Dwarves need to forge titanium?

Why are stats in Angband written as 18/** instead of 19, 20...?

Is there a language that let's you use a try block without a catch block?

Why does a table with a defined constant in its index compute 10X slower?

How to say "that" as in "the cow that ate" in Japanese?

How was the blinking terminal cursor invented?

Why does the setuid bit work inconsistently?

Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?

Merging two rows with rounding their first elemnts

Why is the S-duct intake on the Tu-154 uniquely oblong?

Does the US Supreme Court vote using secret ballots?

At what point can a confirmation be established between words of similar meaning in context?

multicol package causes underfull hbox

Can a generation ship withstand its own oxygen and daily wear for many thousands of years?

Was Tyrion always a poor strategist?

Is it a good idea to teach algorithm courses using pseudocode instead of a real programming language?

Why would you put your input amplifier in front of your filtering for an ECG signal?

How does this piece of code determine array size without using sizeof( )?

How come Arya Stark wasn't hurt by this in Game of Thrones Season 8 Episode 5?

Can an airline pilot be prosecuted for killing an unruly passenger who could not be physically restrained?

Does the usage of mathematical symbols work differently in books than in theses?

Save my secrets!



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







3















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

























  • oh is it? I didnt know.. anyway its immaterial, question still stands :)

    – Carmageddon
    9 hours ago











  • @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
    9 hours ago











  • 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
    9 hours ago











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

    – Carmageddon
    9 hours ago






  • 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
    9 hours ago




















3















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

























  • oh is it? I didnt know.. anyway its immaterial, question still stands :)

    – Carmageddon
    9 hours ago











  • @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
    9 hours ago











  • 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
    9 hours ago











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

    – Carmageddon
    9 hours ago






  • 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
    9 hours ago
















3












3








3








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 50 mins ago









jwodder

192110




192110










asked 9 hours ago









CarmageddonCarmageddon

1216




1216













  • oh is it? I didnt know.. anyway its immaterial, question still stands :)

    – Carmageddon
    9 hours ago











  • @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
    9 hours ago











  • 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
    9 hours ago











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

    – Carmageddon
    9 hours ago






  • 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
    9 hours ago





















  • oh is it? I didnt know.. anyway its immaterial, question still stands :)

    – Carmageddon
    9 hours ago











  • @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
    9 hours ago











  • 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
    9 hours ago











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

    – Carmageddon
    9 hours ago






  • 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
    9 hours ago



















oh is it? I didnt know.. anyway its immaterial, question still stands :)

– Carmageddon
9 hours ago





oh is it? I didnt know.. anyway its immaterial, question still stands :)

– Carmageddon
9 hours ago













@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
9 hours ago





@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
9 hours ago













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
9 hours ago





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
9 hours ago













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

– Carmageddon
9 hours ago





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

– Carmageddon
9 hours ago




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
9 hours ago







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
9 hours ago












1 Answer
1






active

oldest

votes


















6














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
    9 hours ago












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









6














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
    9 hours ago
















6














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
    9 hours ago














6












6








6







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 9 hours ago









Michael HomerMichael Homer

52.3k9144181




52.3k9144181








  • 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
    9 hours ago














  • 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
    9 hours ago








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
9 hours ago





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
9 hours ago


















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







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...