1

so I did this:

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

with the desire for the program to open vi on that path

however, when I execute wtfman it instead returns

Vim: Warning: Output is not to a terminal

what did I do wrong and how do I go about reforming that function so that it opens vi accordingly instead of just complaining? ie I want a command stored in a string and I want to execute the command specified by that string. It works for everything else, but it's not working for vi (could it be because of vi's full screen nature?)

pillarOfLight
  • 8,592
  • 15
  • 60
  • 90
  • possible duplicate of [Why does "locate filename | xargs vim" cause strange terminal behaviour?](http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour) – sehe Oct 17 '13 at 23:24
  • What's wrong with `wtfman() { vi /the/path/file.txt; }`? There's no compelling reason to store the full command, with arguments, in a single variable here. – chepner Oct 18 '13 at 01:35

2 Answers2

1

You're executing in a subshell, use eval instead

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

Or just...

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

Or even just...

function wtfman(){
  vi /the/path/file.txt
}
sehe
  • 374,641
  • 47
  • 450
  • 633
0

Instead of $($command), just write $command. This way, the command will inherit the stdout of the shell rather than having its stdout captured by the shell that invokes it.

William Pursell
  • 204,365
  • 48
  • 270
  • 300