sh sudo string parameter












2















I'm playing with my Raspberry Pi Zero, and I'm trying to automate an FM transmitter script.



You can run the script with sudo fm_transmitter -f [frequency] -r [.wav music file]



For example:



sudo fm_transmitter -f 103 -r star_wars.wav


My code:



musics[0] = "/home/pi/radio/fm/star_wars.wav"

sudo /home/pi/radio/fm/fm_transmitter -f 103 -r musics[0]


It gives me an error because it can't find musics[0].



What could be the problem here?










share|improve this question




















  • 1





    Is this a Bash script or a strictly sh script? Arrays are a Bash thing.

    – Thomas Ward
    Jan 3 at 14:22











  • What are you trying to do with that music[0], is that an array?

    – George Udosen
    Jan 3 at 14:23













  • i want to feed in that star_wars.wav file into -r so i can change it when it finishes

    – Burgerl X
    Jan 3 at 14:23


















2















I'm playing with my Raspberry Pi Zero, and I'm trying to automate an FM transmitter script.



You can run the script with sudo fm_transmitter -f [frequency] -r [.wav music file]



For example:



sudo fm_transmitter -f 103 -r star_wars.wav


My code:



musics[0] = "/home/pi/radio/fm/star_wars.wav"

sudo /home/pi/radio/fm/fm_transmitter -f 103 -r musics[0]


It gives me an error because it can't find musics[0].



What could be the problem here?










share|improve this question




















  • 1





    Is this a Bash script or a strictly sh script? Arrays are a Bash thing.

    – Thomas Ward
    Jan 3 at 14:22











  • What are you trying to do with that music[0], is that an array?

    – George Udosen
    Jan 3 at 14:23













  • i want to feed in that star_wars.wav file into -r so i can change it when it finishes

    – Burgerl X
    Jan 3 at 14:23
















2












2








2








I'm playing with my Raspberry Pi Zero, and I'm trying to automate an FM transmitter script.



You can run the script with sudo fm_transmitter -f [frequency] -r [.wav music file]



For example:



sudo fm_transmitter -f 103 -r star_wars.wav


My code:



musics[0] = "/home/pi/radio/fm/star_wars.wav"

sudo /home/pi/radio/fm/fm_transmitter -f 103 -r musics[0]


It gives me an error because it can't find musics[0].



What could be the problem here?










share|improve this question
















I'm playing with my Raspberry Pi Zero, and I'm trying to automate an FM transmitter script.



You can run the script with sudo fm_transmitter -f [frequency] -r [.wav music file]



For example:



sudo fm_transmitter -f 103 -r star_wars.wav


My code:



musics[0] = "/home/pi/radio/fm/star_wars.wav"

sudo /home/pi/radio/fm/fm_transmitter -f 103 -r musics[0]


It gives me an error because it can't find musics[0].



What could be the problem here?







command-line sudo sh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 19:16









Zanna

51.2k13139243




51.2k13139243










asked Jan 3 at 14:17









Burgerl XBurgerl X

132




132








  • 1





    Is this a Bash script or a strictly sh script? Arrays are a Bash thing.

    – Thomas Ward
    Jan 3 at 14:22











  • What are you trying to do with that music[0], is that an array?

    – George Udosen
    Jan 3 at 14:23













  • i want to feed in that star_wars.wav file into -r so i can change it when it finishes

    – Burgerl X
    Jan 3 at 14:23
















  • 1





    Is this a Bash script or a strictly sh script? Arrays are a Bash thing.

    – Thomas Ward
    Jan 3 at 14:22











  • What are you trying to do with that music[0], is that an array?

    – George Udosen
    Jan 3 at 14:23













  • i want to feed in that star_wars.wav file into -r so i can change it when it finishes

    – Burgerl X
    Jan 3 at 14:23










1




1





Is this a Bash script or a strictly sh script? Arrays are a Bash thing.

– Thomas Ward
Jan 3 at 14:22





Is this a Bash script or a strictly sh script? Arrays are a Bash thing.

– Thomas Ward
Jan 3 at 14:22













What are you trying to do with that music[0], is that an array?

– George Udosen
Jan 3 at 14:23







What are you trying to do with that music[0], is that an array?

– George Udosen
Jan 3 at 14:23















i want to feed in that star_wars.wav file into -r so i can change it when it finishes

– Burgerl X
Jan 3 at 14:23







i want to feed in that star_wars.wav file into -r so i can change it when it finishes

– Burgerl X
Jan 3 at 14:23












1 Answer
1






active

oldest

votes


















5














You've set the first element of an array as /home/pi/radio/fm/star_wars.wav with the line:



musics[0]="/home/pi/radio/fm/star_wars.wav"


To access the contents, you need to expand that array element using $ like so:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "${musics[0]}"


The quotes "" are used to preserve the format of the output, and the braces {} are part of expanding an array variable.



It's not clear why you're using an array here, when a standard variable would work. You could replace:



musics[0]="/home/pi/radio/fm/star_wars.wav"


with



musics="/home/pi/radio/fm/star_wars.wav"


and the line using that variable changes to:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "$musics"


This is much simpler as you don't need to use index numbers (the part referred to by [0]).






share|improve this answer


























  • i tried echo "${musics[0]}" and adding it into the sudo method, but it just says it cant find musics[0](even the echo)

    – Burgerl X
    Jan 3 at 14:30













  • i want to use an array so i can switch songs when they ended

    – Burgerl X
    Jan 3 at 14:32











  • If there are spaces around the = in the first line, the variable won't be assigned. Are you using the Bash shell?

    – Arronical
    Jan 3 at 14:32











  • + it says that musics[0] is not found and i an using bash

    – Burgerl X
    Jan 3 at 14:46













  • Make sure there are no spaces around the =, if it says it can't find musics[0] then it is trying to find the literal string 'musics[0]', which means that you're not trying to expand the variable at all. There is no need to add an echo command into the sudo fm_transmitter ... command.

    – Arronical
    Jan 3 at 14:54












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f1106594%2fsh-sudo-string-parameter%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









5














You've set the first element of an array as /home/pi/radio/fm/star_wars.wav with the line:



musics[0]="/home/pi/radio/fm/star_wars.wav"


To access the contents, you need to expand that array element using $ like so:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "${musics[0]}"


The quotes "" are used to preserve the format of the output, and the braces {} are part of expanding an array variable.



It's not clear why you're using an array here, when a standard variable would work. You could replace:



musics[0]="/home/pi/radio/fm/star_wars.wav"


with



musics="/home/pi/radio/fm/star_wars.wav"


and the line using that variable changes to:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "$musics"


This is much simpler as you don't need to use index numbers (the part referred to by [0]).






share|improve this answer


























  • i tried echo "${musics[0]}" and adding it into the sudo method, but it just says it cant find musics[0](even the echo)

    – Burgerl X
    Jan 3 at 14:30













  • i want to use an array so i can switch songs when they ended

    – Burgerl X
    Jan 3 at 14:32











  • If there are spaces around the = in the first line, the variable won't be assigned. Are you using the Bash shell?

    – Arronical
    Jan 3 at 14:32











  • + it says that musics[0] is not found and i an using bash

    – Burgerl X
    Jan 3 at 14:46













  • Make sure there are no spaces around the =, if it says it can't find musics[0] then it is trying to find the literal string 'musics[0]', which means that you're not trying to expand the variable at all. There is no need to add an echo command into the sudo fm_transmitter ... command.

    – Arronical
    Jan 3 at 14:54
















5














You've set the first element of an array as /home/pi/radio/fm/star_wars.wav with the line:



musics[0]="/home/pi/radio/fm/star_wars.wav"


To access the contents, you need to expand that array element using $ like so:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "${musics[0]}"


The quotes "" are used to preserve the format of the output, and the braces {} are part of expanding an array variable.



It's not clear why you're using an array here, when a standard variable would work. You could replace:



musics[0]="/home/pi/radio/fm/star_wars.wav"


with



musics="/home/pi/radio/fm/star_wars.wav"


and the line using that variable changes to:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "$musics"


This is much simpler as you don't need to use index numbers (the part referred to by [0]).






share|improve this answer


























  • i tried echo "${musics[0]}" and adding it into the sudo method, but it just says it cant find musics[0](even the echo)

    – Burgerl X
    Jan 3 at 14:30













  • i want to use an array so i can switch songs when they ended

    – Burgerl X
    Jan 3 at 14:32











  • If there are spaces around the = in the first line, the variable won't be assigned. Are you using the Bash shell?

    – Arronical
    Jan 3 at 14:32











  • + it says that musics[0] is not found and i an using bash

    – Burgerl X
    Jan 3 at 14:46













  • Make sure there are no spaces around the =, if it says it can't find musics[0] then it is trying to find the literal string 'musics[0]', which means that you're not trying to expand the variable at all. There is no need to add an echo command into the sudo fm_transmitter ... command.

    – Arronical
    Jan 3 at 14:54














5












5








5







You've set the first element of an array as /home/pi/radio/fm/star_wars.wav with the line:



musics[0]="/home/pi/radio/fm/star_wars.wav"


To access the contents, you need to expand that array element using $ like so:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "${musics[0]}"


The quotes "" are used to preserve the format of the output, and the braces {} are part of expanding an array variable.



It's not clear why you're using an array here, when a standard variable would work. You could replace:



musics[0]="/home/pi/radio/fm/star_wars.wav"


with



musics="/home/pi/radio/fm/star_wars.wav"


and the line using that variable changes to:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "$musics"


This is much simpler as you don't need to use index numbers (the part referred to by [0]).






share|improve this answer















You've set the first element of an array as /home/pi/radio/fm/star_wars.wav with the line:



musics[0]="/home/pi/radio/fm/star_wars.wav"


To access the contents, you need to expand that array element using $ like so:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "${musics[0]}"


The quotes "" are used to preserve the format of the output, and the braces {} are part of expanding an array variable.



It's not clear why you're using an array here, when a standard variable would work. You could replace:



musics[0]="/home/pi/radio/fm/star_wars.wav"


with



musics="/home/pi/radio/fm/star_wars.wav"


and the line using that variable changes to:



sudo /home/pi/radio/fm/fm_transmitter -f 103 -r "$musics"


This is much simpler as you don't need to use index numbers (the part referred to by [0]).







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 14:31

























answered Jan 3 at 14:24









ArronicalArronical

13.7k84993




13.7k84993













  • i tried echo "${musics[0]}" and adding it into the sudo method, but it just says it cant find musics[0](even the echo)

    – Burgerl X
    Jan 3 at 14:30













  • i want to use an array so i can switch songs when they ended

    – Burgerl X
    Jan 3 at 14:32











  • If there are spaces around the = in the first line, the variable won't be assigned. Are you using the Bash shell?

    – Arronical
    Jan 3 at 14:32











  • + it says that musics[0] is not found and i an using bash

    – Burgerl X
    Jan 3 at 14:46













  • Make sure there are no spaces around the =, if it says it can't find musics[0] then it is trying to find the literal string 'musics[0]', which means that you're not trying to expand the variable at all. There is no need to add an echo command into the sudo fm_transmitter ... command.

    – Arronical
    Jan 3 at 14:54



















  • i tried echo "${musics[0]}" and adding it into the sudo method, but it just says it cant find musics[0](even the echo)

    – Burgerl X
    Jan 3 at 14:30













  • i want to use an array so i can switch songs when they ended

    – Burgerl X
    Jan 3 at 14:32











  • If there are spaces around the = in the first line, the variable won't be assigned. Are you using the Bash shell?

    – Arronical
    Jan 3 at 14:32











  • + it says that musics[0] is not found and i an using bash

    – Burgerl X
    Jan 3 at 14:46













  • Make sure there are no spaces around the =, if it says it can't find musics[0] then it is trying to find the literal string 'musics[0]', which means that you're not trying to expand the variable at all. There is no need to add an echo command into the sudo fm_transmitter ... command.

    – Arronical
    Jan 3 at 14:54

















i tried echo "${musics[0]}" and adding it into the sudo method, but it just says it cant find musics[0](even the echo)

– Burgerl X
Jan 3 at 14:30







i tried echo "${musics[0]}" and adding it into the sudo method, but it just says it cant find musics[0](even the echo)

– Burgerl X
Jan 3 at 14:30















i want to use an array so i can switch songs when they ended

– Burgerl X
Jan 3 at 14:32





i want to use an array so i can switch songs when they ended

– Burgerl X
Jan 3 at 14:32













If there are spaces around the = in the first line, the variable won't be assigned. Are you using the Bash shell?

– Arronical
Jan 3 at 14:32





If there are spaces around the = in the first line, the variable won't be assigned. Are you using the Bash shell?

– Arronical
Jan 3 at 14:32













+ it says that musics[0] is not found and i an using bash

– Burgerl X
Jan 3 at 14:46







+ it says that musics[0] is not found and i an using bash

– Burgerl X
Jan 3 at 14:46















Make sure there are no spaces around the =, if it says it can't find musics[0] then it is trying to find the literal string 'musics[0]', which means that you're not trying to expand the variable at all. There is no need to add an echo command into the sudo fm_transmitter ... command.

– Arronical
Jan 3 at 14:54





Make sure there are no spaces around the =, if it says it can't find musics[0] then it is trying to find the literal string 'musics[0]', which means that you're not trying to expand the variable at all. There is no need to add an echo command into the sudo fm_transmitter ... command.

– Arronical
Jan 3 at 14:54


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • 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%2faskubuntu.com%2fquestions%2f1106594%2fsh-sudo-string-parameter%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

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen