【问题标题】:executing vi using the bash $ command使用 bash $ 命令执行 vi
【发布时间】:2013-10-26 15:59:10
【问题描述】:

所以我这样做了:

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

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

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

Vim: Warning: Output is not to a terminal

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

【问题讨论】:

标签: linux bash shell terminal vi


【解决方案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
}

【讨论】:

    【解决方案2】:

    不要写$($command),而是写$command。这样,命令将继承 shell 的标准输出,而不是让调用它的 shell 捕获其标准输出。

    【讨论】:

      猜你喜欢
      • 2014-03-27
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      • 2014-01-11
      • 2012-04-05
      • 1970-01-01
      • 2018-12-17
      • 2017-06-26
      相关资源
      最近更新 更多