I want to save a command output to an variable in a bash script. I've tried possibilities that I've found here in this forum but it doesn't work for my script.
I use the command: cangen vcan0 -g 4 -I 7E -L 8 -D r -v
to generate CAN data. -g, -I, -L, -D, -V are parameter to define how the CAN data have to be generate.
Normally i get the data printed on the Terminal like this:
I want to store this output in a variable:
#!/bin/bash
#We have to generate a virtual CAN bus Interface
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
candata= `(cangen vcan0 -g 0.008 -I 7E -L 8 -D r -v)`
echo $candata
and when i run my script, i do not obtain the output from my cangen-command. I get the output:
RTNETLINK answers: File exists
I do not have much experience with Linux and bash script programming. Can someone help me?