分页: 1 / 1

[已解决]echo 'export abc=123' | source /dev/stdin 为何无法设置变量?

发表于 : 2017-08-01 14:22
科学之子
echo 'export abc=123' | source /dev/stdin 为何无法设置变量?
Tue Aug 1 21:37:38 CST 2017补充:
https://superuser.com/questions/705204/ ... 207#705207

Re: echo 'export abc=123' | source /dev/stdin 为何无法设置变量?

发表于 : 2017-08-01 15:55
九天星
因为这是一个字符串

Re: echo 'export abc=123' | source /dev/stdin 为何无法设置变量?

发表于 : 2017-08-01 21:58
科学之子
九天星 写了:因为这是一个字符串
不是您理解的这样

代码: 全选

$ help source
source: source filename [arguments]
    Execute commands from a file in the current shell.
    
    Read and execute commands from FILENAME in the current shell.  The
    entries in $PATH are used to find the directory containing FILENAME.
    If any ARGUMENTS are supplied, they become the positional parameters
    when FILENAME is executed.
    
    Exit Status:
    Returns the status of the last command executed in FILENAME; fails if
    FILENAME cannot be read.
source命令是在当前shell执行命令,命令执行环境跟用户手动输入执行时是一样的
本意是想把echo的输入重定向给source去执行,但管线(Pipiline)会再开一个新的shell去执行source
"Process Substitution"(<(list))的结果是list的标准输出文件
例如:

代码: 全选

$ echo <(date)
/dev/fd/63
此帖的提问主要是为了解决这个问题.

Re: [已解决]echo 'export abc=123' | source /dev/stdin 为何无法设置变量?

发表于 : 2017-08-02 18:09
九天星
你知道还问

Re: [已解决]echo 'export abc=123' | source /dev/stdin 为何无法设置变量?

发表于 : 2017-08-02 21:36
科学之子
九天星 写了:你知道还问
:em06
我也是才知道的...