I am trying to create a simple alias that uses the argument with the full path
On the command line, I can type command "$(pwd)/my_file". It works. so I tried to create an alias in the following way:
alias command='command "$(pwd)/$1"'
This alias didn't work though. The CLI interprets as if $(pwd) and my_file were separated arguments... I tried to use the eval command to turn my command into a single one
alias command="eval 'command' '$(pwd)/$1'"
However, it keeps waiting for an input argument instead of taking my initial argument...
If you wanna try out what I mean, substitute command for the evince (a popular PDF viewer) and my_file for any PDF file. So my alias is
alias evince="evince $(pwd)/$1"
In my case, $(pwd) is /home/tapyu/Downloads/, and my_file is recap.pdf. I know that evince is treating it as a separated argument because it pops up two windows: The first one opens recap.pdf properly. The second is an empty window with a warning "Error opening file, /home/tapyu/Downloads/ is a directory."
Thank you in advance.
PS: I know that this "problem" is pointless. My problem is not "how to give the full path to a command", my problem is "how to handle inputs argument in an alias in order to solve this kind of situation". So don't wanna alternatives to give the full path, I wanna know why my alias is not working.
$(pwd)andmy_fileas two separate arguments when you define your alias as you show first? How do you actually try to use that alias? Also, aliases do not take arguments. They are simple text replacements. Your second alias makes no sense unless you have set$1to something at the time of defining the alias (but it's still not what you want, I guess). I believe you may be wanting to use a shell function, but I'm still confused about your talk about "separate arguments".command my_fileand that is exactly the same ascommand $(pwd)/my_file.alias command="eval 'command' '$(pwd)/$1'", the shell keeps expanding it recursively forever (useset -xto see it). You may use... eval '\command' ...instead (the backslash prevents alias expansion), but all the points in the previous comments would still stand.evinceexample) it opens two windows: The first one opens thefileproperly. The second is an empty window with a warning "Error opening file,<pwd-path>is a directory.".