如何在终端直接运行自己的程序?
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
-
- 帖子: 70
- 注册时间: 2007-12-26 15:56
- 来自: MIT
如何在终端直接运行自己的程序?
我自己编了一个程序,生成了可执行文件,在/home/XX/test/test1。我想在终端里敲test1直接运行,应该怎样做?请高手赐教!
- Daphne
- 帖子: 39
- 注册时间: 2008-02-25 14:30
-
- 帖子: 70
- 注册时间: 2007-12-26 15:56
- 来自: MIT
- Daphne
- 帖子: 39
- 注册时间: 2008-02-25 14:30
-
- 帖子: 70
- 注册时间: 2007-12-26 15:56
- 来自: MIT
我按你说的第一种方法没有成功啊,按你说的是不是在test下面不过多少个可执行文件都可以执行了?Daphne 写了:环境变量内添加path
比如你使用bash
进入自己的主目录,即输入cd后面不加东西,回车
vi .bashrc (有个点哦)
在后面添加 export PATH=/home/xxx/test:$PATH
然后保存退出
然后. .bashrc (两个点中间有空格哦)
然后再输入test1试下?
如果你只是要临时的,在终端下输入
PATH=/home/xxx/test:$PATH 回车
再输入test1试下呢?
不过这样你把当前终端关了变量就失效了哦
那系统自带的可执行文件是怎么设置在终端里敲名字就能直接运行的阿?
- Daphne
- 帖子: 39
- 注册时间: 2008-02-25 14:30
请确认自己使用的是bash,而且是修改当前用户主目录下的.bashrc,并且两个路径中间是使用了英文的:分割,并且确定已经保存修改
最后. .bashrc了。
系统中的环境变量为:vi /etc/environment
如果你用的不是ubuntu,比如red hat系列,而且你使用的是bash,请查看/etc/profile
不建议把你那个学习用的PATH加入。最多就是象第一种方法那样修改个人用户的环境变量就好
建议先学下linux基础 - -||
环境变量配置的章节。
最后. .bashrc了。
系统中的环境变量为:vi /etc/environment
如果你用的不是ubuntu,比如red hat系列,而且你使用的是bash,请查看/etc/profile
不建议把你那个学习用的PATH加入。最多就是象第一种方法那样修改个人用户的环境变量就好
建议先学下linux基础 - -||
环境变量配置的章节。
上次由 Daphne 在 2008-02-28 10:54,总共编辑 1 次。
-
- 帖子: 70
- 注册时间: 2007-12-26 15:56
- 来自: MIT
-
- 帖子: 70
- 注册时间: 2007-12-26 15:56
- 来自: MIT
- Daphne
- 帖子: 39
- 注册时间: 2008-02-25 14:30
http://irc.ubuntu.org.cn/irc.cgiDaniel23 写了:Daphne
Can I ask u some question? I'm in Nanjing too! working on ubuntu.
can u tell me your email?
这里的大牛很多
- xhy
- 帖子: 3916
- 注册时间: 2005-12-28 1:16
- 系统: Ubuntu 12.10 X64
- 来自: 火星
: /etc/profile
//全局初始化文件,作用于登录式shell
: /etc/bashrc
//标准bash没有定义这个配置文件
: ~/.bashrc
//每一个交互式shell的初始化文件
: ~/.bash_profile
//个人初始化文件,在执行完/etc/profile后执行,作用于登录式shell
如果你从TTY登录,输入用户名和秘密,
那么首先执行/etc/profile然后执行~/.bash_profile
(从TTY登录的shell是以-开头的)
如果在X中打开终端,那么执行~/.bashrc
一些概念: 登录式Shell,交互式Shell
INVOCATION
A login shell is one whose first character of argument zero is a -, or
one started with the --login option.
An interactive shell is one started without non-option arguments and
without the -c option whose standard input and error are both connected
to terminals (as determined by isatty(3)), or one started with the -i
option. PS1 is set and $- includes i if bash is interactive, allowing
a shell script or a startup file to test this state.
The following paragraphs describe how bash executes its startup files.
If any of the files exist but cannot be read, bash reports an error.
Tildes are expanded in file names as described below under Tilde Expan-
sion in the EXPANSION section.
When bash is invoked as an interactive login shell, or as a non-inter-
active shell with the --login option, it first reads and executes com-
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.
When a login shell exits, bash reads and executes commands from the
file ~/.bash_logout, if it exists.
When an interactive shell that is not a login shell is started, bash
reads and executes commands from ~/.bashrc, if that file exists. This
may be inhibited by using the --norc option. The --rcfile file option
will force bash to read and execute commands from file instead of
~/.bashrc.
When bash is started non-interactively, to run a shell script, for
example, it looks for the variable BASH_ENV in the environment, expands
its value if it appears there, and uses the expanded value as the name
of a file to read and execute. Bash behaves as if the following com-
mand were executed:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the PATH variable is not used to search for the file
name.
//全局初始化文件,作用于登录式shell
: /etc/bashrc
//标准bash没有定义这个配置文件
: ~/.bashrc
//每一个交互式shell的初始化文件
: ~/.bash_profile
//个人初始化文件,在执行完/etc/profile后执行,作用于登录式shell
如果你从TTY登录,输入用户名和秘密,
那么首先执行/etc/profile然后执行~/.bash_profile
(从TTY登录的shell是以-开头的)
如果在X中打开终端,那么执行~/.bashrc
一些概念: 登录式Shell,交互式Shell
INVOCATION
A login shell is one whose first character of argument zero is a -, or
one started with the --login option.
An interactive shell is one started without non-option arguments and
without the -c option whose standard input and error are both connected
to terminals (as determined by isatty(3)), or one started with the -i
option. PS1 is set and $- includes i if bash is interactive, allowing
a shell script or a startup file to test this state.
The following paragraphs describe how bash executes its startup files.
If any of the files exist but cannot be read, bash reports an error.
Tildes are expanded in file names as described below under Tilde Expan-
sion in the EXPANSION section.
When bash is invoked as an interactive login shell, or as a non-inter-
active shell with the --login option, it first reads and executes com-
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.
When a login shell exits, bash reads and executes commands from the
file ~/.bash_logout, if it exists.
When an interactive shell that is not a login shell is started, bash
reads and executes commands from ~/.bashrc, if that file exists. This
may be inhibited by using the --norc option. The --rcfile file option
will force bash to read and execute commands from file instead of
~/.bashrc.
When bash is started non-interactively, to run a shell script, for
example, it looks for the variable BASH_ENV in the environment, expands
its value if it appears there, and uses the expanded value as the name
of a file to read and execute. Bash behaves as if the following com-
mand were executed:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the PATH variable is not used to search for the file
name.
目前负债150多万
-
- 帖子: 133
- 注册时间: 2007-12-26 8:02
- gaint_star
- 帖子: 413
- 注册时间: 2008-02-20 0:09
- 来自: 深圳
- 联系:
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系: