gpt4 book ai didi

linux - 使用 bash $ 命令执行 vi

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:01:40 25 4
gpt4 key购买 nike

所以我这样做了:

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

希望程序在该路径上打开 vi

但是,当我执行 wtfman 时,它会返回

Vim: Warning: Output is not to a terminal

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

最佳答案

您正在子 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
}

关于linux - 使用 bash $ 命令执行 vi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19438969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com