I’m trying to create an alias for an application for easy access rather than going to the directory and running it.
alias cpanel-run='"$(cd /home/ian/projects/electron/cpanel-linux-x64/)" "$(cpanel)"'
but it only displays
bash: ./cpanel: No such file or directory
Command '' not found, but can be installed with:
sudo apt install bpfcc-tools # version 0.8.0-4, or
sudo apt install mailutils-mh # version 1:3.5-2build1
sudo apt install mmh # version 0.4-2
sudo apt install nmh # version 1.7.1-4
2
Answers
Do you actually need to be in the same directory as the executable? If not, just do this:
If you do need to be in the same directory, use this instead:
(The
&&
tells the shell to run the first (cd
) command, and then run the second only if that succeeds.)The reason your original version didn’t work is that you’re using
$()
inappropriately. What$()
does is run its contents as a subprocess collect the output, and use that as part of the command line. So, your version runs thecd
command, which successfully changes to the directory, but since it runs as a subprocess it has no effect on your shell or any other process. It also produces no output. Then the other$()
tries to runcpanel
(is it actually./cpanel
?) in a different subprocess, fails because it’s not there (producing the first error message), and also produces no output. Then, based on the (empty) output from those two subprocesses, the shell tries to run the command"" ""
, which fails because the empty string is not a valid command.Please refer below, I used to like this, and if you need to run open a terminal and just type kibana or elasticsearch whatever the alias name.
Please note you have to put these lines bottom of the .bashrc file