sh sudo string parameter
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
New contributor
add a comment |
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
New contributor
1
Is this a Bash script or a strictlysh
script? Arrays are a Bash thing.
– Thomas Ward♦
5 hours ago
What are you trying to do with thatmusic[0]
, is that an array?
– George Udosen
5 hours ago
i want to feed in that star_wars.wav file into -r so i can change it when it finishes
– Burgerl X
5 hours ago
add a comment |
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
New contributor
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
command-line sudo sh
New contributor
New contributor
edited 55 mins ago
Zanna
50.1k13131240
50.1k13131240
New contributor
asked 5 hours ago
Burgerl X
111
111
New contributor
New contributor
1
Is this a Bash script or a strictlysh
script? Arrays are a Bash thing.
– Thomas Ward♦
5 hours ago
What are you trying to do with thatmusic[0]
, is that an array?
– George Udosen
5 hours ago
i want to feed in that star_wars.wav file into -r so i can change it when it finishes
– Burgerl X
5 hours ago
add a comment |
1
Is this a Bash script or a strictlysh
script? Arrays are a Bash thing.
– Thomas Ward♦
5 hours ago
What are you trying to do with thatmusic[0]
, is that an array?
– George Udosen
5 hours ago
i want to feed in that star_wars.wav file into -r so i can change it when it finishes
– Burgerl X
5 hours ago
1
1
Is this a Bash script or a strictly
sh
script? Arrays are a Bash thing.– Thomas Ward♦
5 hours ago
Is this a Bash script or a strictly
sh
script? Arrays are a Bash thing.– Thomas Ward♦
5 hours ago
What are you trying to do with that
music[0]
, is that an array?– George Udosen
5 hours ago
What are you trying to do with that
music[0]
, is that an array?– George Udosen
5 hours ago
i want to feed in that star_wars.wav file into -r so i can change it when it finishes
– Burgerl X
5 hours ago
i want to feed in that star_wars.wav file into -r so i can change it when it finishes
– Burgerl X
5 hours ago
add a comment |
1 Answer
1
active
oldest
votes
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]).
i triedecho "${musics[0]}"
and adding it into the sudo method, but it just says it cant find musics[0](even the echo)
– Burgerl X
5 hours ago
i want to use an array so i can switch songs when they ended
– Burgerl X
5 hours ago
If there are spaces around the=
in the first line, the variable won't be assigned. Are you using the Bash shell?
– Arronical
5 hours ago
+ it says that musics[0] is not found and i an using bash
– Burgerl X
5 hours ago
Make sure there are no spaces around the=
, if it says it can't findmusics[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 thesudo fm_transmitter ...
command.
– Arronical
5 hours ago
|
show 5 more comments
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.
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%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
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]).
i triedecho "${musics[0]}"
and adding it into the sudo method, but it just says it cant find musics[0](even the echo)
– Burgerl X
5 hours ago
i want to use an array so i can switch songs when they ended
– Burgerl X
5 hours ago
If there are spaces around the=
in the first line, the variable won't be assigned. Are you using the Bash shell?
– Arronical
5 hours ago
+ it says that musics[0] is not found and i an using bash
– Burgerl X
5 hours ago
Make sure there are no spaces around the=
, if it says it can't findmusics[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 thesudo fm_transmitter ...
command.
– Arronical
5 hours ago
|
show 5 more comments
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]).
i triedecho "${musics[0]}"
and adding it into the sudo method, but it just says it cant find musics[0](even the echo)
– Burgerl X
5 hours ago
i want to use an array so i can switch songs when they ended
– Burgerl X
5 hours ago
If there are spaces around the=
in the first line, the variable won't be assigned. Are you using the Bash shell?
– Arronical
5 hours ago
+ it says that musics[0] is not found and i an using bash
– Burgerl X
5 hours ago
Make sure there are no spaces around the=
, if it says it can't findmusics[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 thesudo fm_transmitter ...
command.
– Arronical
5 hours ago
|
show 5 more comments
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]).
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]).
edited 5 hours ago
answered 5 hours ago
Arronical
13.1k84790
13.1k84790
i triedecho "${musics[0]}"
and adding it into the sudo method, but it just says it cant find musics[0](even the echo)
– Burgerl X
5 hours ago
i want to use an array so i can switch songs when they ended
– Burgerl X
5 hours ago
If there are spaces around the=
in the first line, the variable won't be assigned. Are you using the Bash shell?
– Arronical
5 hours ago
+ it says that musics[0] is not found and i an using bash
– Burgerl X
5 hours ago
Make sure there are no spaces around the=
, if it says it can't findmusics[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 thesudo fm_transmitter ...
command.
– Arronical
5 hours ago
|
show 5 more comments
i triedecho "${musics[0]}"
and adding it into the sudo method, but it just says it cant find musics[0](even the echo)
– Burgerl X
5 hours ago
i want to use an array so i can switch songs when they ended
– Burgerl X
5 hours ago
If there are spaces around the=
in the first line, the variable won't be assigned. Are you using the Bash shell?
– Arronical
5 hours ago
+ it says that musics[0] is not found and i an using bash
– Burgerl X
5 hours ago
Make sure there are no spaces around the=
, if it says it can't findmusics[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 thesudo fm_transmitter ...
command.
– Arronical
5 hours 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
5 hours 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
5 hours ago
i want to use an array so i can switch songs when they ended
– Burgerl X
5 hours ago
i want to use an array so i can switch songs when they ended
– Burgerl X
5 hours ago
If there are spaces around the
=
in the first line, the variable won't be assigned. Are you using the Bash shell?– Arronical
5 hours ago
If there are spaces around the
=
in the first line, the variable won't be assigned. Are you using the Bash shell?– Arronical
5 hours ago
+ it says that musics[0] is not found and i an using bash
– Burgerl X
5 hours ago
+ it says that musics[0] is not found and i an using bash
– Burgerl X
5 hours 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
5 hours 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
5 hours ago
|
show 5 more comments
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.
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.
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%2faskubuntu.com%2fquestions%2f1106594%2fsh-sudo-string-parameter%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
1
Is this a Bash script or a strictly
sh
script? Arrays are a Bash thing.– Thomas Ward♦
5 hours ago
What are you trying to do with that
music[0]
, is that an array?– George Udosen
5 hours ago
i want to feed in that star_wars.wav file into -r so i can change it when it finishes
– Burgerl X
5 hours ago