Dave Marchant
Dave Marchant

Reputation: 23

How do I prompt for user input in bash? Please fix my python/bash Spanglish

Sorry. I am very new to this and can't find a straight forward answer. In python I can say:

from sys import argv
script, user_name = argv
prompt'> '
print "Hi %s, I'm the %s script" % (user_name, script)
print "I'd like to ask you a few questions"
print "What channel is that on?"
channel = raw_input(prompt)
blah blah -c %r  % (channel)

I need to be able to either accomplish the same thing with raw_input() in a regular bash (.sh) shell script OR I need to be able to manipulate other programs from within a python script OR I need to be able to launch a second shell (bash)from within a python script.

Please be gentle.

Upvotes: 2

Views: 305

Answers (2)

Alessandro Pezzato
Alessandro Pezzato

Reputation: 8822

I guess you are looking for read internal command

echo -n "What channel is that on? ";
read channel;

Or more concisely

read -p "What channel is that on? " channel

Upvotes: 4

ThatAintWorking
ThatAintWorking

Reputation: 1360

Look at the subprocess module if you want to launch other programs from python. As for manipulating other programs -- you'd have to be more specific about the manipulation but I have found that I can do everything in python that I used to do in bash plus a whole lot more. If you are new to python, you should be sleeping with the Library Reference under your pillow. I've been doing python for years and I still refer to it a lot when I am programming.

Upvotes: 0

Related Questions