Question

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?)

Was it helpful?

Solution

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
}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top