Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-24-2006, 11:05 AM   #1
Registered: Jun 2005
Location: Kentucky
Distribution: Ubuntu
Posts: 794

Rep: Reputation: 56
Shell Scripts Answering Prompts

I'm still a newb at writing shell scripts. I've figured out enough to make them run commands to automate things but I have a question. If I know a command will be met with a prompting question (password, yes or no to install dependancies, etc.) could I write in the script how to go about answering such prompts so if I were to run a long script it would automatically answer the questions for me?
Old 01-24-2006, 11:20 AM   #2
Senior Member
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Yes, but you'll need to use a different language to write the script, like TCL/Expect. For example:

#!/usr/bin/expect -f
# wrapper to make passwd(1) be non-interactive
# username is passed as 1st arg, passwd as 2nd
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect "assword:"
send -- "$password\r"
expect "assword:"
send -- "$password\r"
expect eof

If you Google for TCL/Expect, you'll find loads of resources. Creating simple responses is really very straight forward.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell scripts newbie_m Linux - Newbie 3 01-18-2005 08:12 PM
Shell prompts and keymaps amnesty_puppy Linux - Newbie 8 08-17-2004 06:52 PM
Shell Prompts and root ls colouring iantri Slackware 10 09-11-2003 08:48 PM
shell scripts nautilus_1987 Linux - General 3 08-30-2002 03:12 AM
shell scripts gui10 Programming 10 10-28-2001 02:46 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:30 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration