Pipe echo of associative array into dmenu

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















I have this script:



#!/bin/bash

declare -a arr
arr+=(
[mirror]="xrandr --output hdmi-1 --same-as edp-1"
[extend]="xrandr --output hdmi-1 --auto"
)
screen=hdmi-1

chosen=$(echo -e $!arr[@]| dmenu -fn monospace-14)

[ "$chosen" != "" ] || exit


But when I run this, mirror and extend are the same item.



Is there a way to get this into two separate items?



To print multiple items you do this:



echo -e "firstnsecondnthird" | dmenu


I used an associative array because then I only need to write the options once, and adding options is very easy (just append the list).










share|improve this question
























  • Are you wanting to use bash or sh? Your code explicitly uses sh but the question is tagged bash. Please clarify. n. b. I'm pretty sure sh does not have associative arrays.

    – DopeGhoti
    Jan 8 at 19:19











  • @DopeGhoti Im using bash. Thats a typo sry

    – Felix Rosén
    Jan 8 at 19:23






  • 2





    Shouldn't it be declare -A (upper case) for an associative array (as opposed to declare -a for an indexed array)?

    – steeldriver
    Jan 8 at 19:36











  • +1 That is so amazingl! I never heard about declare -A before. I am feeling like a idiot for all scripts that I wrote without knowing about that. So that is the OP's problem.

    – Luciano Andress Martini
    Jan 8 at 19:38
















1















I have this script:



#!/bin/bash

declare -a arr
arr+=(
[mirror]="xrandr --output hdmi-1 --same-as edp-1"
[extend]="xrandr --output hdmi-1 --auto"
)
screen=hdmi-1

chosen=$(echo -e $!arr[@]| dmenu -fn monospace-14)

[ "$chosen" != "" ] || exit


But when I run this, mirror and extend are the same item.



Is there a way to get this into two separate items?



To print multiple items you do this:



echo -e "firstnsecondnthird" | dmenu


I used an associative array because then I only need to write the options once, and adding options is very easy (just append the list).










share|improve this question
























  • Are you wanting to use bash or sh? Your code explicitly uses sh but the question is tagged bash. Please clarify. n. b. I'm pretty sure sh does not have associative arrays.

    – DopeGhoti
    Jan 8 at 19:19











  • @DopeGhoti Im using bash. Thats a typo sry

    – Felix Rosén
    Jan 8 at 19:23






  • 2





    Shouldn't it be declare -A (upper case) for an associative array (as opposed to declare -a for an indexed array)?

    – steeldriver
    Jan 8 at 19:36











  • +1 That is so amazingl! I never heard about declare -A before. I am feeling like a idiot for all scripts that I wrote without knowing about that. So that is the OP's problem.

    – Luciano Andress Martini
    Jan 8 at 19:38














1












1








1








I have this script:



#!/bin/bash

declare -a arr
arr+=(
[mirror]="xrandr --output hdmi-1 --same-as edp-1"
[extend]="xrandr --output hdmi-1 --auto"
)
screen=hdmi-1

chosen=$(echo -e $!arr[@]| dmenu -fn monospace-14)

[ "$chosen" != "" ] || exit


But when I run this, mirror and extend are the same item.



Is there a way to get this into two separate items?



To print multiple items you do this:



echo -e "firstnsecondnthird" | dmenu


I used an associative array because then I only need to write the options once, and adding options is very easy (just append the list).










share|improve this question
















I have this script:



#!/bin/bash

declare -a arr
arr+=(
[mirror]="xrandr --output hdmi-1 --same-as edp-1"
[extend]="xrandr --output hdmi-1 --auto"
)
screen=hdmi-1

chosen=$(echo -e $!arr[@]| dmenu -fn monospace-14)

[ "$chosen" != "" ] || exit


But when I run this, mirror and extend are the same item.



Is there a way to get this into two separate items?



To print multiple items you do this:



echo -e "firstnsecondnthird" | dmenu


I used an associative array because then I only need to write the options once, and adding options is very easy (just append the list).







bash shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 12 at 15:24









Jeff Schaller

39.9k1054126




39.9k1054126










asked Jan 8 at 19:14









Felix RosénFelix Rosén

1135




1135












  • Are you wanting to use bash or sh? Your code explicitly uses sh but the question is tagged bash. Please clarify. n. b. I'm pretty sure sh does not have associative arrays.

    – DopeGhoti
    Jan 8 at 19:19











  • @DopeGhoti Im using bash. Thats a typo sry

    – Felix Rosén
    Jan 8 at 19:23






  • 2





    Shouldn't it be declare -A (upper case) for an associative array (as opposed to declare -a for an indexed array)?

    – steeldriver
    Jan 8 at 19:36











  • +1 That is so amazingl! I never heard about declare -A before. I am feeling like a idiot for all scripts that I wrote without knowing about that. So that is the OP's problem.

    – Luciano Andress Martini
    Jan 8 at 19:38


















  • Are you wanting to use bash or sh? Your code explicitly uses sh but the question is tagged bash. Please clarify. n. b. I'm pretty sure sh does not have associative arrays.

    – DopeGhoti
    Jan 8 at 19:19











  • @DopeGhoti Im using bash. Thats a typo sry

    – Felix Rosén
    Jan 8 at 19:23






  • 2





    Shouldn't it be declare -A (upper case) for an associative array (as opposed to declare -a for an indexed array)?

    – steeldriver
    Jan 8 at 19:36











  • +1 That is so amazingl! I never heard about declare -A before. I am feeling like a idiot for all scripts that I wrote without knowing about that. So that is the OP's problem.

    – Luciano Andress Martini
    Jan 8 at 19:38

















Are you wanting to use bash or sh? Your code explicitly uses sh but the question is tagged bash. Please clarify. n. b. I'm pretty sure sh does not have associative arrays.

– DopeGhoti
Jan 8 at 19:19





Are you wanting to use bash or sh? Your code explicitly uses sh but the question is tagged bash. Please clarify. n. b. I'm pretty sure sh does not have associative arrays.

– DopeGhoti
Jan 8 at 19:19













@DopeGhoti Im using bash. Thats a typo sry

– Felix Rosén
Jan 8 at 19:23





@DopeGhoti Im using bash. Thats a typo sry

– Felix Rosén
Jan 8 at 19:23




2




2





Shouldn't it be declare -A (upper case) for an associative array (as opposed to declare -a for an indexed array)?

– steeldriver
Jan 8 at 19:36





Shouldn't it be declare -A (upper case) for an associative array (as opposed to declare -a for an indexed array)?

– steeldriver
Jan 8 at 19:36













+1 That is so amazingl! I never heard about declare -A before. I am feeling like a idiot for all scripts that I wrote without knowing about that. So that is the OP's problem.

– Luciano Andress Martini
Jan 8 at 19:38






+1 That is so amazingl! I never heard about declare -A before. I am feeling like a idiot for all scripts that I wrote without knowing about that. So that is the OP's problem.

– Luciano Andress Martini
Jan 8 at 19:38











0






active

oldest

votes











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%2f493310%2fpipe-echo-of-associative-array-into-dmenu%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f493310%2fpipe-echo-of-associative-array-into-dmenu%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

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay