2013-10-17 104 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。