How to pipe results multiple results into a command?How to do a control loopHow to set multiple env variables from stdout pipePipe 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

Divisor Rich and Poor Numbers

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

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

Why do academics prefer Mac/Linux?

Who is frowning in the sentence "Daisy looked at Tom frowning"?

Combining two Lorentz boosts

Is it possible to determine from only a photo of a cityscape whether it was taken close with wide angle or from a distance with zoom?

French equivalent of the German expression "flöten gehen"

Gambler's Fallacy Dice

Driving a school bus in the USA

What technology would Dwarves need to forge titanium?

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

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

Good examples of "two is easy, three is hard" in computational sciences

Can 2 light bulbs of 120V in series be used on 230V AC?

Using `printf` to print variable containing `%` percent sign results in "bash: printf: `p': invalid format character"

What color to choose as "danger" if the main color of my app is red

Former Employer just sent me an IP Agreement

What should I wear to go and sign an employment contract?

How was the blinking terminal cursor invented?

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

Why does string strummed with finger sound different from the one strummed with pick?

Appropriate liquid/solvent for life in my underground environment on Venus

Are there any symmetric cryptosystems based on computational complexity assumptions?



How to pipe results multiple results into a command?


How to do a control loopHow to set multiple env variables from stdout pipePipe 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;








4















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, like like:



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











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

    – Carmageddon
    4 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
    4 hours ago


















4















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, like like:



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











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

    – Carmageddon
    4 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
    4 hours ago














4












4








4








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, like like:



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, like like:



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







Carmageddon

















asked 4 hours ago









CarmageddonCarmageddon

1235




1235












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

    – Carmageddon
    4 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
    4 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
    4 hours ago











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

    – Carmageddon
    4 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
    4 hours ago


















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

    – Carmageddon
    4 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
    4 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
    4 hours ago











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

    – Carmageddon
    4 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
    4 hours ago

















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

– Carmageddon
4 hours ago





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

– Carmageddon
4 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
4 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
4 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
4 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
4 hours ago













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

– Carmageddon
4 hours ago





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

– Carmageddon
4 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
4 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
4 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
    3 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-results-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
    3 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
    3 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 3 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
    3 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
    3 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
3 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
3 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-results-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

Log på Navigationsmenu

Creating second map without labels using QGIS?How to lock map labels for inset map in Print Composer?How to Force the Showing of Labels of a Vector File in QGISQGIS Valmiera, Labels only show for part of polygonsRemoving duplicate point labels in QGISLabeling every feature using QGIS?Show labels for point features outside map canvasAbbreviate Road Labels in QGIS only when requiredExporting map from composer in QGIS - text labels have moved in output?How to make sure labels in qgis turn up in layout map?Writing label expression with ArcMap and If then Statement?

Detroit Tigers Spis treści Historia | Skład zespołu | Sukcesy | Członkowie Baseball Hall of Fame | Zastrzeżone numery | Przypisy | Menu nawigacyjneEncyclopedia of Detroit - Detroit TigersTigers Stadium, Detroit, MITigers Timeline 1900sDetroit Tigers Team History & EncyclopediaTigers Timeline 1910s1935 World Series1945 World Series1945 World Series1984 World SeriesComerica Park, Detroit, MI2006 World Series2012 World SeriesDetroit Tigers 40-Man RosterDetroit Tigers Coaching StaffTigers Hall of FamersTigers Retired Numberse