Pipe echo of associative array into dmenu
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
Are you wanting to usebash
orsh
? Your code explicitly usessh
but the question is taggedbash
. Please clarify. n. b. I'm pretty suresh
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 bedeclare -A
(upper case) for an associative array (as opposed todeclare -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
add a comment |
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
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
bash shell-script
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 usebash
orsh
? Your code explicitly usessh
but the question is taggedbash
. Please clarify. n. b. I'm pretty suresh
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 bedeclare -A
(upper case) for an associative array (as opposed todeclare -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
add a comment |
Are you wanting to usebash
orsh
? Your code explicitly usessh
but the question is taggedbash
. Please clarify. n. b. I'm pretty suresh
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 bedeclare -A
(upper case) for an associative array (as opposed todeclare -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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Are you wanting to use
bash
orsh
? Your code explicitly usessh
but the question is taggedbash
. Please clarify. n. b. I'm pretty suresh
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 todeclare -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