2013-10-17 106 views
1

所以我这样做:

function wtfman(){ 
    local command="vi /the/path/file.txt" 
    $($command) 
} 

与程序打开VI这条道路上

然而,渴望当我执行wtfman它,而不是返回

Vim: Warning: Output is not to a terminal 

我做错了什么,我该如何去改革这个功能,以便它相应地打开vi而不是只是抱怨?即我想要一个存储在一个字符串中的命令,我想执行该字符串指定的命令。它适用于其他所有,但它不适用于vi(可能是因为vi的全屏性质?)

+0

的可能重复[为什么“locate filename | xargs vim”导致奇怪的终端行为?](http://stackoverflow.com/questions/8228831/why-does-locate-filename-x args-vim-cause-strange-terminal-behavior) – sehe

+0

'wtfman(){vi /the/path/file.txt; }'?没有充分的理由将完整的命令和参数存储在单个变量中。 – chepner

回答

1

你是在一个子shell执行,使用eval代替

function wtfman(){ 
    local command="vi /the/path/file.txt" 
    eval "$command" 
} 

或者只是......

function wtfman(){ 
    local command="vi /the/path/file.txt" 
    $command 
} 

甚至只是......

function wtfman(){ 
    vi /the/path/file.txt 
} 
0

而不是$($command),只需写$command。这样,该命令将继承shell的stdout,而不是通过调用它的shell捕获它的stdout。