passing arguments to shell script from udev rules file
environment-variables, export, shell, udev, variables
Solution
You should be able to use single quotes instead of the double quotes you mentioned:
ACTION=="add", RUN+="/appmount/scripts/usb_mount.sh '%E{ID_FS_LABEL}' '%E{DEVNAME}'"
Beware: I didn't test this. Maybe variable substitution will fail within single quotes...
Quoting from `man udev` about the key "RUN":
The program name and following arguments are separated by spaces. Single quotes can be used to specify arguments with spaces.
Problem
In the rules file a script is executed by passing the arguments "LABEL" and "DEVNAME" for mounting ``` ACTION=="add", RUN+="/appmount/scripts/usb_mount.sh %E{ID_FS_LABEL} %E{DEVNAME}" ``` In the usb_mount.sh file printing the arguments value as ``` echo "LABEL: $1 DEVNAME: $2" # this does not work reliably ``` Some of the devices have empty LABEL field and hence the DEVNAME is printed as the label. In the bash script we can pass the args in double quotes and it will work even if the args are null. What is the equivalent of the same for passing args to udev rules? The workaround to this problem might be to switch the order of the arguments. Is there any reliable way?