I have this script:


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

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 "first\nsecond\nthird" | 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).

  • 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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.