sh sudo string parametr












2














I'm playing with my Raspberry Pi Zero, and I'm trying to automate 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 cant find "musics[0]"



Please help me I'm new to sh










share|improve this question









New contributor




Burgerl X is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Is this a Bash script or a strictly sh script? Arrays are a Bash thing.
    – Thomas Ward
    1 hour ago










  • What are you trying to do with that music[0], is that an array?
    – George Udosen
    1 hour ago












  • i want to feed in that star_wars.wav file into -r so i can change it when it finishes
    – Burgerl X
    1 hour ago


















2














I'm playing with my Raspberry Pi Zero, and I'm trying to automate 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 cant find "musics[0]"



Please help me I'm new to sh










share|improve this question









New contributor




Burgerl X is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Is this a Bash script or a strictly sh script? Arrays are a Bash thing.
    – Thomas Ward
    1 hour ago










  • What are you trying to do with that music[0], is that an array?
    – George Udosen
    1 hour ago












  • i want to feed in that star_wars.wav file into -r so i can change it when it finishes
    – Burgerl X
    1 hour ago
















2












2








2







I'm playing with my Raspberry Pi Zero, and I'm trying to automate 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 cant find "musics[0]"



Please help me I'm new to sh










share|improve this question









New contributor




Burgerl X is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm playing with my Raspberry Pi Zero, and I'm trying to automate 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 cant find "musics[0]"



Please help me I'm new to sh







sudo sh






share|improve this question









New contributor




Burgerl X is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Burgerl X is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago









Arronical

13.1k84790




13.1k84790






New contributor




Burgerl X is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









Burgerl X

111




111




New contributor




Burgerl X is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Burgerl X is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Burgerl X is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    Is this a Bash script or a strictly sh script? Arrays are a Bash thing.
    – Thomas Ward
    1 hour ago










  • What are you trying to do with that music[0], is that an array?
    – George Udosen
    1 hour ago












  • i want to feed in that star_wars.wav file into -r so i can change it when it finishes
    – Burgerl X
    1 hour ago
















  • 1




    Is this a Bash script or a strictly sh script? Arrays are a Bash thing.
    – Thomas Ward
    1 hour ago










  • What are you trying to do with that music[0], is that an array?
    – George Udosen
    1 hour ago












  • i want to feed in that star_wars.wav file into -r so i can change it when it finishes
    – Burgerl X
    1 hour ago










1




1




Is this a Bash script or a strictly sh script? Arrays are a Bash thing.
– Thomas Ward
1 hour ago




Is this a Bash script or a strictly sh script? Arrays are a Bash thing.
– Thomas Ward
1 hour ago












What are you trying to do with that music[0], is that an array?
– George Udosen
1 hour ago






What are you trying to do with that music[0], is that an array?
– George Udosen
1 hour ago














i want to feed in that star_wars.wav file into -r so i can change it when it finishes
– Burgerl X
1 hour ago






i want to feed in that star_wars.wav file into -r so i can change it when it finishes
– Burgerl X
1 hour ago












1 Answer
1






active

oldest

votes


















4














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
    1 hour ago












  • i want to use an array so i can switch songs when they ended
    – Burgerl X
    58 mins ago










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










  • + it says that musics[0] is not found and i an using bash
    – Burgerl X
    44 mins ago












  • 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
    36 mins ago











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
});


}
});






Burgerl X is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1106594%2fsh-sudo-string-parametr%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









4














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
    1 hour ago












  • i want to use an array so i can switch songs when they ended
    – Burgerl X
    58 mins ago










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










  • + it says that musics[0] is not found and i an using bash
    – Burgerl X
    44 mins ago












  • 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
    36 mins ago
















4














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
    1 hour ago












  • i want to use an array so i can switch songs when they ended
    – Burgerl X
    58 mins ago










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










  • + it says that musics[0] is not found and i an using bash
    – Burgerl X
    44 mins ago












  • 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
    36 mins ago














4












4








4






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 1 hour ago

























answered 1 hour ago









Arronical

13.1k84790




13.1k84790












  • 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
    1 hour ago












  • i want to use an array so i can switch songs when they ended
    – Burgerl X
    58 mins ago










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










  • + it says that musics[0] is not found and i an using bash
    – Burgerl X
    44 mins ago












  • 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
    36 mins ago


















  • 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
    1 hour ago












  • i want to use an array so i can switch songs when they ended
    – Burgerl X
    58 mins ago










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










  • + it says that musics[0] is not found and i an using bash
    – Burgerl X
    44 mins ago












  • 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
    36 mins ago
















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
1 hour ago






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
1 hour ago














i want to use an array so i can switch songs when they ended
– Burgerl X
58 mins ago




i want to use an array so i can switch songs when they ended
– Burgerl X
58 mins ago












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




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












+ it says that musics[0] is not found and i an using bash
– Burgerl X
44 mins ago






+ it says that musics[0] is not found and i an using bash
– Burgerl X
44 mins ago














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
36 mins ago




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
36 mins ago










Burgerl X is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Burgerl X is a new contributor. Be nice, and check out our Code of Conduct.













Burgerl X is a new contributor. Be nice, and check out our Code of Conduct.












Burgerl X is a new contributor. Be nice, and check out our Code of Conduct.
















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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-parametr%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

Eastern Orthodox Church

Zagreb

Understanding the information contained in the Deep Space Network XML data?