原帖由 FH 于 2007-1-2 08:33 发表
当bash以sh为名运行时,在交互非login模式下,其继承了所有环境变量(包括任何用户定义的变量),唯独不继承PS*!
号称是靠向POSIX,但是俺用过的所有Unix(AIX、HPUX、SCO)的sh,在该模式下都是继承PS*变量的。
俺的环境:bash 3.00
原帖由 langue 于 2007-1-2 09:00 发表
这种现象变态但合法而和谐地存在着。
/etc/profile.d/MyPrompt.sh
export PS1='${PWD}> '
/etc/profile.d/MyPrompt.csh
set prompt='%/> '
/etc/bashrc
......
export ENV=/etc/profile
原帖由 FH 于 2007-1-2 08:33 发表
当bash以sh为名运行时,在交互非login模式下,其继承了所有环境变量(包括任何用户定义的变量),唯独不继承PS*!
号称是靠向POSIX,但是俺用过的所有Unix(AIX、HPUX、SCO)的sh,在该模式下都是继承PS*变量的。 ...
原帖由 kenduest 于 2007-1-2 13:12 发表
其实,你的问题最有可能的只是,因为你当初用的系统都是把 PS1 宣告为 export/environment variable,而不是一般 local 性质变数,所以才会有这种差异。
这样吧?你还有在那些的 AIX,HUPX 等系统吗?你可不 ...
原帖由 FH 于 2007-1-2 21:19 发表
晕!
你自己试一下就知道了
俺Unix玩了十多年,Linux也玩了十年了,什么问题俺还看不清?
原帖由 kenduest 于 2007-1-3 01:09 发表
态度好像蛮高傲的 ?
PS1 本来就不是 export variable,所以怎么会有环境变量复制继承的特性呢?所以问题拉回来看,若你只是要能够 PS1 变量继承下去,请把 PS1 变量设定为 export variable 就可以了,不就 ...
原帖由 FH 于 2007-1-3 09:39 发表
晕!你没看懂俺的问题吧?知道啥叫交互非login模式不?
你进vi,然后:!sh,再告诉俺有没有PS1!
真是你说的那么简单的事,俺都不好意思发帖子!
原帖由 kenduest 于 2007-1-3 16:25 发表
请上 GNU 的 coreutils mailing list 去回应你的问题,我想 developer 可以解决你的问题。因为在这边抱怨 bash 如何变态问题还是无解。
--
原帖由 FH 于 2007-1-3 17:08 发表
看清楚好不好,俺给出了解决方案,而不是像某人那样问题都没有看清也不实验就开始信口开河。
原帖由 kenduest 于 2007-1-4 00:18 发表
看不出来你给了啥解决方案 ?
我等你好消息啊,不要忘记对 GNU coreutils mailing list 反应后的结果呈报一下。
--
原帖由 FH 于 2007-1-4 08:58 发表
晕!4楼不是么?
就你这种看帖方式还申请版主?
但愿不要误杀、误导大家,阿门!
原帖由 bdwy 于 2007-1-4 15:42 发表
汗S
FH不觉得确实有些过分么
人家好心好意,就算错了不是也得跟人说声谢谢
虽然我不懂这个,不知道谁对谁错
原帖由 FH 于 2007-1-2 21:19 发表
晕!
你自己试一下就知道了
俺Unix玩了十多年,Linux也玩了十年了,什么问题俺还看不清?
晕!你没看懂俺的问题吧?知道啥叫交互非login模式不?
你进vi,然后:!sh,再告诉俺有没有PS1!
真是你说的那么简单的事,俺都不好意思发帖子!
原帖由 yjh777 于 2007-1-4 16:08 发表
看不看得清,跟玩儿了几年没关系!
这个问题确实不复杂,学知识没什么好意思不好意思的。
你的态度确实过分!应该学孔夫子三省乎己了。
原帖由 FH 于 2007-1-2 08:33 发表
当bash以sh为名运行时,在交互非login模式下,其继承了所有环境变量(包括任何用户定义的变量),唯独不继承PS*!
号称是靠向POSIX,但是俺用过的所有Unix(AIX、HPUX、SCO)的sh,在该模式下都是继承PS*变量的。 ...
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.
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.
If bash is invoked with the name sh, it tries to mimic the startup
behavior of historical versions of sh as closely as possible, while
conforming to the POSIX standard as well. When invoked as an interac‐\r
tive login shell, or a non-interactive shell with the --login option,
it first attempts to read and execute commands from /etc/profile and
~/.profile, in that order. The --noprofile option may be used to
inhibit this behavior. When invoked as an interactive shell with the
name sh, bash looks for the variable ENV, expands its value if it is
defined, and uses the expanded value as the name of a file to read and
execute. Since a shell invoked as sh does not attempt to read and exe‐\r
cute commands from any other startup files, the --rcfile option has no
effect. A non-interactive shell invoked with the name sh does not
attempt to read any other startup files. When invoked as sh, bash
enters posix mode after the startup files are read.
When bash is started in posix mode, as with the --posix command line
option, it follows the POSIX standard for startup files. In this mode,
interactive shells expand the ENV variable and commands are read and
executed from the file whose name is the expanded value. No other
startup files are read.
原帖由 FH 于 2007-1-9 19:19 发表
楼上的确很细致,佩服!
俺的是RHEL-AS4,俺也是man了以后找到的这个方法。
俺试了一下,如果直接在shell下面执行sh,是能够继承PS1的,但是进入了vi就不行了,从其它程序访问sh应该也是这样(推理),但是同样 ...
xxx@linux:~> echo $ENV
xxx@linux:~> vi
:!sh
sh-2.05b$ exit
:q!
xxx@linux:~> echo $PS1
\u@\h:\w>
xxx@linux:~> export PS1
xxx@linux:~> vi
:!sh
sh-2.05b$ exit
:q!
原帖由 FH 于 2007-1-10 08:44 发表
to 楼上:
export PS1俺是绝对不会疏忽遗忘的,因此才有变态一说。
刚刚在SUSE LINUX Enterprise Server 9 (i586) - Kernel 2.6.5-7.97-bigsmp上试验,结果一如RHEL-AS4。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |