i have a expect script like

spawn passwd
expect "password:"
send "password"

Wile executing this, I'm unable to run bash script test.sh.

How to execute Linux commands/bash scripts inside Expect script?


To begin with you should use spawn to run your script, and I'm not certain the tilde construct will be interpreted by expect.

spawn /bin/bash /home/username/test.sh

You should have error messages when this happens, you should add the to your question if you do not understand them.


You can use the tcl exec command, which normally collects the output, so redirect it:

exec ~/test.sh  >@stdout

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.