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

gatorback
  • 1,384
  • 23
  • 48

1 Answers1

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

jiipeezz
  • 231
  • 2
  • 5
  • 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 '16 at 21:04