1

I'm writing a script to log serial data from an USB port to file and I'm using script and picocom to log the data as such:

sudo script -a -c 'sudo picocom /dev/ttyUSB0 | ts "%Y-%b-%d %H:%M:%S10"' /usr/local/logs/device1.log

which works ok and I want to wrap it in an openPort script so I can call openPort device1 USB0. So far I've got

sudo script -a -c 'sudo picocom /dev/tty"${2}" | ts "%Y-%b-%d %H:%M:%S10"' /usr/local/logs/${1}.log

which unfortunately doesn't open the COM port. I think the problem is that script launches a new session which executes sudo picocom /dev/tty"{2}" instead of using the argument passed from openPort. Is there a way to pass the argument properly?

2

Everything inside single quotes is not expanded, so just remove this parameter from the quotes:

sudo script -a -c 'sudo picocom /dev/tty'"${2}"' | ts "%Y-%b-%d %H:%M:%S10"' /usr/local/logs/${1}.log

Shell will take care of merging all parts together.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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