0

I have a function

fz(){file=$(find | fzf) && echo $file && read order && $("$order" "$file")}

in my .zshrz. It allows me to look up for a file anywhere in a subdirectory relative of where I call it from, and then apply a command specified by my input to that file.

Only there's a slight problem: while the function works as intended if $order is anything but an alias specifed in the same .zshrc file, it shoots a "command not found" should I use any of my aliases.

Is there a way to use aliases stored as variables within zsh functions?

0

You need to use eval instead of $( … ). This works:

fz() {
  file=$( find | fzf )
  echo $file
  read order
  eval "$order $file"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.