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.logwhich works ok and I want to wrap it in an openPort script so I can call openPort device1 USB0. So far I've gotsudo script -a -c 'sudo picocom /dev/tty${2} | ts %Y-%b-%d %H:%M:%S10' /usr/local/logs/${1}.logwhich 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?
Passing argument from a shell script to a new session
linux;usb;typescript
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}.logShell will take care of merging all parts together.