skip to Main Content

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


  1. Do you actually need to be in the same directory as the executable? If not, just do this:

    alias cpanel-run='/home/ian/projects/electron/cpanel-linux-x64/cpanel'
    

    If you do need to be in the same directory, use this instead:

    alias cpanel-run='cd /home/ian/projects/electron/cpanel-linux-x64/ && ./cpanel'
    

    (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 the cd 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 run cpanel (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.

    Login or Signup to reply.
  2. 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

    alias kibana='cd /home/bhanuka/Apps/ELK/kibana-7.5.2-linux-x86_64/bin/ && ./kibana'
    alias elasticsearch='cd /home/bhanuka/Apps/ELK/elasticsearch-7.5.2-linux-x86_64/elasticsearch-7.5.2/bin/ && ./elasticsearch'
    alias logstash='cd /home/bhanuka/Apps/ELK/logstash-7.5.2/bin/ && ./logstash'
    alias filebeat='cd /home/bhanuka/Apps/ELK/filebeat-7.5.2-linux-x86_64/ && ./filebeat -e'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search