如何在bash中提示用户输入?请修复我的python / bash Spanglish

时间:2011-11-26 16:22:49

标签: python bash

对不起。我对此很陌生,无法找到直接的答案。在python我可以说:

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)

我需要能够在常规bash(.sh)shell脚本中使用raw_input()完成相同的操作 OR 我需要能够在python脚本中操作其他程序 OR 我需要能够在python脚本中启动第二个shell(bash)。

请保持温和。

2 个答案:

答案 0 :(得分:4)

我猜您正在寻找read内部命令

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

或者更简洁

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

答案 1 :(得分:0)

如果要从python启动其他程序,请查看subprocess模块。至于操纵其他程序 - 你必须更加具体的操作,但我发现我可以在python中做我曾经在bash中做的所有事情以及更多。如果你是python的新手,你应该睡在枕头下的Library Reference。我已经做了多年的python,在编程时我仍然会参考它。