4

An Ubuntu 16.04 udev rule is defined:

target='SUBSYSTEMS=="usb", ATTRS{product}=="Metrologic Scanner", GROUP:="username"'

Command to append a rule to test udev file fails:

sudo echo $target > /etc/udev/rules.d/test.txt

What must be done to overcome the response \ error:

bash: /etc/udev/rules.d/test.txt: Permission denied

Examples and explanations are highly appreciated: thank you

0

1 Answer 1

4

You could use this instead and it will work

echo "$target" | sudo tee --append /etc/udev/rules.d/test.txt

tee command with --append (shortly -a) option appends the echoed string to the specified file, nothing is overwritten. tee also writes to STDOUT which can be redirected to /dev/null if desired

Another way to do this is

sudo bash -c 'echo "$target" > /etc/udev/rules.d/test.txt'

but I do recommend sticking with the first example, because echo "$target" will be run without root privileges

1
  • It would be helpful \ constructive \ good if each solution had an explanation and the why of the recommendation. Selected as accepted answer.
    – gatorback
    Nov 26, 2016 at 21:04

Not the answer you're looking for? Browse other questions tagged .