在bash shell中使用python? [英] using python at the bash shell?

查看:61
本文介绍了在bash shell中使用python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我刚刚安装了Ubuntu,我正在学习如何使用bash

shell。除了你可以使用的普通命令之外,我想知道是否可以从终端使用Python而不是普通的bash

命令(例如打印而不是
)回声)。我要问的主要原因是

我喜欢用Python做任何事情,如果我不需要学习

bash''语言'',那么我还不够。


谢谢。

Hi all. I just installed Ubuntu and I''m learning how to use the bash
shell. Aside from the normal commands you can use, I was wondering if
it''s possible to use Python from the terminal instead of the normal bash
commands (e.g. print instead of echo). My main reason for asking is that
I like using Python for everything, and if I don''t need to learn the
bash ''language'', then I won''t just yet.

Thanks.

推荐答案

On Mon,2006-08-07在21:03 - 0400,John Salerno写道:
On Mon, 2006-08-07 at 21:03 -0400, John Salerno wrote:

大家好。我刚刚安装了Ubuntu,我正在学习如何使用bash

shell。除了你可以使用的普通命令之外,我想知道是否可以从终端使用Python而不是普通的bash

命令(例如打印而不是
)回声)。
Hi all. I just installed Ubuntu and I''m learning how to use the bash
shell. Aside from the normal commands you can use, I was wondering if
it''s possible to use Python from the terminal instead of the normal bash
commands (e.g. print instead of echo).


>从终端窗口输入,
>From a terminal window typing,



python -c" print ''测试''"


将产生与


echo''测试''
bash shell中的
,但显然不那么好。

python -c "print ''testing''"

would produce the same results as

echo ''testing''

in bash shell, but obviously not as nice.


我问的主要原因是

我喜欢使用Python对于一切,如果我不需要学习

bash''语言'',那么我还不会。
My main reason for asking is that
I like using Python for everything, and if I don''t need to learn the
bash ''language'', then I won''t just yet.



只需键入python并在python解释器中执行您的操作。这个

成为你的shell。


这让我思考,如何让python成为你的登录shell。所以

我将/ etc / passwd中的shell登录条目修改为/ usr / bin / python,

登录后瞧,我的友好python shell被提供了

打开终端窗口。


所以答案是是。


-

此邮件已通过MailScanner扫描病毒和

危险内容,并且

被认为是干净的。

Just type python and do your stuff in the python interpreter. This
becomes your shell.

This then got me thinking, how about making python your login shell. So
I modified my shell login entry in /etc/passwd to /usr/bin/python,
logged in and voila, I was presented with my friendly python shell upon
opening a terminal window.

So the answer is "Yes".

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




JohnAside来自您可以使用的常规命令,我想知道是否可以使用来自终端而不是

Johnnormal bash命令(例如打印而不是回声)。


看看ipython< http://ipython.scipy。组织/取代。这并不是你要求的,但是它提供了一些有助于将Python

与shell环境集成的功能。


Skip

JohnAside from the normal commands you can use, I was wondering if
Johnit''s possible to use Python from the terminal instead of the
Johnnormal bash commands (e.g. print instead of echo).

Take a look at ipython <http://ipython.scipy.org/>. It''s not precisely what
you''ve asked for, but it provides some features that help integrate Python
with the shell environment.

Skip


sk**@pobox.com 已写:

JohnAside来自您可以使用的常规命令,我想知道是否可以使用来自终端的Python

Johnnormal bash命令(例如打印而不是回声)。


看看ipython< http://ipython.scipy.org/取代。这并不是你要求的,但是它提供了一些有助于将Python

与shell环境集成的功能。


跳过
JohnAside from the normal commands you can use, I was wondering if
Johnit''s possible to use Python from the terminal instead of the
Johnnormal bash commands (e.g. print instead of echo).

Take a look at ipython <http://ipython.scipy.org/>. It''s not precisely what
you''ve asked for, but it provides some features that help integrate Python
with the shell environment.

Skip



FWIW,我是第二个。如果你想使用python作为你的shell使用

Ipython。这真是太好了。费尔南多·佩雷斯做了一件好事恕我直言。


一定要阅读(或至少略读)手册:
http://ipython.scipy.org/doc/manual/index.html

这是一个调用man ls的例子。然后得到

" ls -l"的结果进入一个python列表(每行一个列表项)然后提取

MANIFEST文件的大小(作为字符串)...享受...(我希望

重新格式化并没有太糟糕。)

FWIW, I second this. If you want to use python as your shell use
Ipython. It''s just great. Fernando Pérez has done a Good Thing IMHO.

Be sure to read (or at least skim) the manual:
http://ipython.scipy.org/doc/manual/index.html

Here''s an example of calling "man ls" and then getting the results of
"ls -l" into a python list (one list item per line) and then extracting
the size (as a string) of the MANIFEST file... Enjoy... (I hope
reformatting doesn''t screw this up too badly.)


这篇关于在bash shell中使用python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆