Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.