pillarOfLight
pillarOfLight

Reputation: 8982

executing vi using the bash $ command

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

Upvotes: 1

Views: 306

Answers (2)

sehe
sehe

Reputation: 393009

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
}

Upvotes: 1

William Pursell
William Pursell

Reputation: 212248

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.

Upvotes: 0

Related Questions