向终端输出命令? [英] outputting a command to the terminal?

查看:57
本文介绍了向终端输出命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的新项目:我想写一个小脚本,我可以在终端输入

,如下所示:


$ scriptname package1 [package2,...]

其中scriptname是我的模块名,任何后续参数都是要安装的Linux软件包的

名称。运行上面的脚本将

创建这一行:


sudo aptitude install package1 package2 ...


它将在终端运行该行,以便安装包。


现在,我想要添加的额外功能(否则我只会

正常安装它们!)是将包名保存到文本文件中所以我现在可以手动安装程序的名称,如果我想要

检查列表或删​​除包。


所以创建正确的bash命令(sudo aptitude install ...)很简单,

并编写名称到文件很容易。但是我有两个问题:


1.首先,Linux是否会手动跟踪您的软件包

安装?如果是这样,那么我根本不需要这样做。


2.假设我写这个,如何输出bash命令到

终端?是否有一个Python用来与之交互的特定模块

我可以用来将安装命令发送到

终端的终端窗口?


谢谢。

Here''s my new project: I want to write a little script that I can type
at the terminal like this:

$ scriptname package1 [package2, ...]

where scriptname is my module name and any subsequent arguments are the
names of Linux packages to install. Running the script as above will
create this line:

sudo aptitude install package1 package2 ...

It will run that line at the terminal so the package(s) will be installed.

Now, the extra functionality I want to add (otherwise I would just
install them normally!) is to save the package names to a text file so I
can now the names of programs I''ve manually installed, if I ever want to
check the list or remove packages.

So creating the proper bash command (sudo aptitude install ...) is easy,
and writing the names to a file is easy. But I have two questions:

1. First of all, does Linux keep track of the packages you manually
install? If so, then I won''t have to do this at all.

2. Assuming I write this, how do output the bash command to the
terminal? Is there a particular module that Python uses to interact with
the terminal window that I can use to send the install command to the
terminal?

Thanks.

推荐答案

scriptname package1 [package2,...]


其中scriptname是我的模块名称,任何后续参数都是要安装的Linux软件包的名称。运行上面的脚本将

创建这一行:


sudo aptitude install package1 package2 ...


它将在终端运行该行,以便安装包。


现在,我想要添加的额外功能(否则我只会

正常安装它们!)是将包名保存到文本文件中所以我现在可以手动安装程序的名称,如果我想要

检查列表或删​​除包。


所以创建正确的bash命令(sudo aptitude install ...)很简单,

并编写名称到文件很容易。但是我有两个问题:


1.首先,Linux是否会手动跟踪您的软件包

安装?如果是这样,那么我根本不需要这样做。


2.假设我写这个,如何输出bash命令到

终端?是否有一个Python用来与之交互的特定模块

我可以用来将安装命令发送到

终端的终端窗口?


谢谢。
scriptname package1 [package2, ...]

where scriptname is my module name and any subsequent arguments are the
names of Linux packages to install. Running the script as above will
create this line:

sudo aptitude install package1 package2 ...

It will run that line at the terminal so the package(s) will be installed.

Now, the extra functionality I want to add (otherwise I would just
install them normally!) is to save the package names to a text file so I
can now the names of programs I''ve manually installed, if I ever want to
check the list or remove packages.

So creating the proper bash command (sudo aptitude install ...) is easy,
and writing the names to a file is easy. But I have two questions:

1. First of all, does Linux keep track of the packages you manually
install? If so, then I won''t have to do this at all.

2. Assuming I write this, how do output the bash command to the
terminal? Is there a particular module that Python uses to interact with
the terminal window that I can use to send the install command to the
terminal?

Thanks.


John Salerno schrieb:
John Salerno schrieb:

这是我的新项目:我想写一个小脚本,我可以在终端输入

,如下所示:

Here''s my new project: I want to write a little script that I can type
at the terminal like this:


scriptname package1 [package2 ,. ..]


其中scriptname是我的模块名称,任何后续参数都是要安装的Linux软件包的

名称。运行上面的脚本将

创建这一行:


sudo aptitude install package1 package2 ...


它将在终端运行该行,以便安装包。


现在,我想要添加的额外功能(否则我只会

正常安装它们!)是将包名保存到文本文件中所以我现在可以手动安装程序的名称,如果我想要

检查列表或删​​除包。


所以创建正确的bash命令(sudo aptitude install ...)很简单,

并编写名称到文件很容易。但是我有两个问题:


1.首先,Linux是否会手动跟踪您的软件包

安装?如果是这样,那么我根本不需要这样做。


2.假设我写这个,如何输出bash命令到

终端?是否有一个特定的模块,Python用来与

终端窗口进行交互,我可以使用它来将安装命令发送到

终端?
scriptname package1 [package2, ...]

where scriptname is my module name and any subsequent arguments are the
names of Linux packages to install. Running the script as above will
create this line:

sudo aptitude install package1 package2 ...

It will run that line at the terminal so the package(s) will be installed.

Now, the extra functionality I want to add (otherwise I would just
install them normally!) is to save the package names to a text file so I
can now the names of programs I''ve manually installed, if I ever want to
check the list or remove packages.

So creating the proper bash command (sudo aptitude install ...) is easy,
and writing the names to a file is easy. But I have two questions:

1. First of all, does Linux keep track of the packages you manually
install? If so, then I won''t have to do this at all.

2. Assuming I write this, how do output the bash command to the
terminal? Is there a particular module that Python uses to interact with
the terminal window that I can use to send the install command to the
terminal?



你没有把命令交给终端。 shell执行命令。

但它主要只是一个程序本身 - 它可以产生子进程和

使它们执行实际的命令。所以 - 您需要的模块最多可能是子流程。


Diez


You don''t put a command to the terminal. The shell executes commands.
But it is mainly just a program itself - it can spawn subprocesses and
make these execute the actual commands. so - the module you need is most
probably subprocess.

Diez


这篇关于向终端输出命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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