udev rules with a math expression
I have a udev rule that creates a symlink for serial devices (USB serial ports) using an expression like this: SYMLINK+="MyDevice_%n"
. The %n assigns the system device node number starting with 0. Is there a way to modify the numbering - instead of %n, perhaps %n+1? Math expressions don't work in a udev rule. I might be able to use a bash script to do the equivalent of echo $((%n+1))
but I'm not sure how to do this in a udev rule. Any helpful suggestions?
serial-port udev
add a comment |
I have a udev rule that creates a symlink for serial devices (USB serial ports) using an expression like this: SYMLINK+="MyDevice_%n"
. The %n assigns the system device node number starting with 0. Is there a way to modify the numbering - instead of %n, perhaps %n+1? Math expressions don't work in a udev rule. I might be able to use a bash script to do the equivalent of echo $((%n+1))
but I'm not sure how to do this in a udev rule. Any helpful suggestions?
serial-port udev
add a comment |
I have a udev rule that creates a symlink for serial devices (USB serial ports) using an expression like this: SYMLINK+="MyDevice_%n"
. The %n assigns the system device node number starting with 0. Is there a way to modify the numbering - instead of %n, perhaps %n+1? Math expressions don't work in a udev rule. I might be able to use a bash script to do the equivalent of echo $((%n+1))
but I'm not sure how to do this in a udev rule. Any helpful suggestions?
serial-port udev
I have a udev rule that creates a symlink for serial devices (USB serial ports) using an expression like this: SYMLINK+="MyDevice_%n"
. The %n assigns the system device node number starting with 0. Is there a way to modify the numbering - instead of %n, perhaps %n+1? Math expressions don't work in a udev rule. I might be able to use a bash script to do the equivalent of echo $((%n+1))
but I'm not sure how to do this in a udev rule. Any helpful suggestions?
serial-port udev
serial-port udev
edited Jan 5 '14 at 20:30
JimFred
asked Jul 9 '13 at 3:43
JimFredJimFred
1,03177
1,03177
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Use the udev rules PROGRAM field to execute a /bin/sh echo expression and capture the result using %c, like this...
PROGRAM="/bin/sh -c 'echo $((%n+1))'", SYMLINK+="MyDevice_%c"
The resulting symlink will have the equivalent of MyDevice_$((%n+1))
or MyDevice_1
if %n is zero. The $(()) construct is called "arithmetic expansion" and causes the contents to be evaluated as an integer expression. It's a syntax element of the shell.
add a comment |
Use ++%n
to start the counter from 0 (MyDevice_0
)
PROGRAM="/bin/sh -c 'echo $((++%n))'", SYMLINK+="MyDevice_%c"
2
Maybe you mean "to start the counter from 1"? Starting at 0 is exactly what OP doesn't want :)
– wazoox
Jan 18 at 17:52
Oops, I misread the OP. Sorry. Yeah, there is no need to usePROGRAM
at all to start with 0 since you can simply use%n
– PooSH
Jan 20 at 8:04
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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
});
}
});
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%2fsuperuser.com%2fquestions%2f617302%2fudev-rules-with-a-math-expression%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the udev rules PROGRAM field to execute a /bin/sh echo expression and capture the result using %c, like this...
PROGRAM="/bin/sh -c 'echo $((%n+1))'", SYMLINK+="MyDevice_%c"
The resulting symlink will have the equivalent of MyDevice_$((%n+1))
or MyDevice_1
if %n is zero. The $(()) construct is called "arithmetic expansion" and causes the contents to be evaluated as an integer expression. It's a syntax element of the shell.
add a comment |
Use the udev rules PROGRAM field to execute a /bin/sh echo expression and capture the result using %c, like this...
PROGRAM="/bin/sh -c 'echo $((%n+1))'", SYMLINK+="MyDevice_%c"
The resulting symlink will have the equivalent of MyDevice_$((%n+1))
or MyDevice_1
if %n is zero. The $(()) construct is called "arithmetic expansion" and causes the contents to be evaluated as an integer expression. It's a syntax element of the shell.
add a comment |
Use the udev rules PROGRAM field to execute a /bin/sh echo expression and capture the result using %c, like this...
PROGRAM="/bin/sh -c 'echo $((%n+1))'", SYMLINK+="MyDevice_%c"
The resulting symlink will have the equivalent of MyDevice_$((%n+1))
or MyDevice_1
if %n is zero. The $(()) construct is called "arithmetic expansion" and causes the contents to be evaluated as an integer expression. It's a syntax element of the shell.
Use the udev rules PROGRAM field to execute a /bin/sh echo expression and capture the result using %c, like this...
PROGRAM="/bin/sh -c 'echo $((%n+1))'", SYMLINK+="MyDevice_%c"
The resulting symlink will have the equivalent of MyDevice_$((%n+1))
or MyDevice_1
if %n is zero. The $(()) construct is called "arithmetic expansion" and causes the contents to be evaluated as an integer expression. It's a syntax element of the shell.
answered Jul 9 '13 at 4:56
JimFredJimFred
1,03177
1,03177
add a comment |
add a comment |
Use ++%n
to start the counter from 0 (MyDevice_0
)
PROGRAM="/bin/sh -c 'echo $((++%n))'", SYMLINK+="MyDevice_%c"
2
Maybe you mean "to start the counter from 1"? Starting at 0 is exactly what OP doesn't want :)
– wazoox
Jan 18 at 17:52
Oops, I misread the OP. Sorry. Yeah, there is no need to usePROGRAM
at all to start with 0 since you can simply use%n
– PooSH
Jan 20 at 8:04
add a comment |
Use ++%n
to start the counter from 0 (MyDevice_0
)
PROGRAM="/bin/sh -c 'echo $((++%n))'", SYMLINK+="MyDevice_%c"
2
Maybe you mean "to start the counter from 1"? Starting at 0 is exactly what OP doesn't want :)
– wazoox
Jan 18 at 17:52
Oops, I misread the OP. Sorry. Yeah, there is no need to usePROGRAM
at all to start with 0 since you can simply use%n
– PooSH
Jan 20 at 8:04
add a comment |
Use ++%n
to start the counter from 0 (MyDevice_0
)
PROGRAM="/bin/sh -c 'echo $((++%n))'", SYMLINK+="MyDevice_%c"
Use ++%n
to start the counter from 0 (MyDevice_0
)
PROGRAM="/bin/sh -c 'echo $((++%n))'", SYMLINK+="MyDevice_%c"
answered Jan 18 at 13:34
PooSHPooSH
111
111
2
Maybe you mean "to start the counter from 1"? Starting at 0 is exactly what OP doesn't want :)
– wazoox
Jan 18 at 17:52
Oops, I misread the OP. Sorry. Yeah, there is no need to usePROGRAM
at all to start with 0 since you can simply use%n
– PooSH
Jan 20 at 8:04
add a comment |
2
Maybe you mean "to start the counter from 1"? Starting at 0 is exactly what OP doesn't want :)
– wazoox
Jan 18 at 17:52
Oops, I misread the OP. Sorry. Yeah, there is no need to usePROGRAM
at all to start with 0 since you can simply use%n
– PooSH
Jan 20 at 8:04
2
2
Maybe you mean "to start the counter from 1"? Starting at 0 is exactly what OP doesn't want :)
– wazoox
Jan 18 at 17:52
Maybe you mean "to start the counter from 1"? Starting at 0 is exactly what OP doesn't want :)
– wazoox
Jan 18 at 17:52
Oops, I misread the OP. Sorry. Yeah, there is no need to use
PROGRAM
at all to start with 0 since you can simply use %n
– PooSH
Jan 20 at 8:04
Oops, I misread the OP. Sorry. Yeah, there is no need to use
PROGRAM
at all to start with 0 since you can simply use %n
– PooSH
Jan 20 at 8:04
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f617302%2fudev-rules-with-a-math-expression%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