linux Installation Automation

Installing the expect Command and Using It for Automation

Shou Arisaka
1 min read
Oct 5, 2025

“expect” is a means of automating dialogue in the bash console.

sudo apt-get install -y expect

When doing git push to GitHub, interactivity occurs. Username and password. We’ll automate this input to make it automatic.

#!/usr/bin/expect

set USER [lindex $argv 0]
set PW [lindex $argv 1]
set Prompt "\[#$%>\]"

set timeout 5

spawn git push
expect {
    -glob "Username for 'https://github.com':" {
        send -- "${USER}\n"
    }
}

expect {
    -glob "Password for 'https://${USER}@github.com':" {
        send -- "${PW}\n"
    }
}

expect {
    -glob "${Prompt}" {
        # interact
        exit 0
    }
}

How to Use

  1. Rename the above script to something like ~/lib/github.exp
  2. $ ~/lib/github.exp USERNAME PASSWORD
  3. You can push to GitHub. (As a prerequisite, create a repository. If "Everything up-to-date" etc. is displayed, it's ok)

Reference: http://qiita.com/ine1127/items/cd6bc91174635016db9b

Share this article

Shou Arisaka Oct 5, 2025

🔗 Copy Links