I'm connecting to a device via screen that requires that I enter some credentials (username and password). It's getting annoying to do that on every entry, so I'd like to alias a command to do that for me:

This alias in ~/.bash_aliases is insufficient:

alias devlogin="sudo screen /dev/ttyACM0 9600 && '\rmyusername' && \rmypassword"

2 Answers 2


Does it have to be screen? Another option is to instead use expect or similar to open the device, issue whatever commands are necessary, and then turn things over to the user. This has the advantage of keeping the password out of the command line (where it is often visible across the system):

#!/usr/bin/env expect

# open up serial and configure
set fh [open /dev/ttyACM0 {RDWR NOCTTY NONBLOCK}]
fconfigure $fh -mode 9600,n,8,1

# link above up with expect
spawn -noecho -open $fh
send -- "\rmyuser"
send -- "\rHunter2"

# over to the user now

Using stuff with the right syntax seems to work:

alias evdlogin="sudo screen /dev/ttyACM0 9600 -X stuff $'\rmyusername\rmypassword'"

Note that it's generally bad practice to hard-code a password in plain text, but since this is a development environment...


You must log in to answer this question.

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