Run executable file on terminal

  • I'm new to Ubuntu and currently on it because of assignment. I would like to ask few questions:

    1. How do I make new command to run a shell script? For example, when you type passwd on terminal it runs the executable file on /usr/bin/passwd. How do I make it the same like my file?

    2. How do I change my shell script into a executable file like the passwd?

  • Your script should look like:


    Save it in a file, let say or simple password, then make it executable using next commands in terminal:

    cd /path/to/  #or cd /path/to/password
    chmod +x     #or chmod +x password

    To run it from terminal, just use the following command:

    ./            #or ./password


    /path/to/     #or /path/to/password

    To run it only using:              #or password

    you must to add the path of the script to the PATH. See How to add a directory to the PATH? in this sense.

    I want to run it without the "./" part. Is it possible?

    I'm sorry, I forgotten another criteria which is I want to run with out the ".sh" also. That means I want to run my file with just the file name on terminal. For example: passwd

    @Guest Ok, save the script eith the name `password`. There is no problem by doing this.

    Cool. Will try it out soon. Thanks alot for your help.

    You should change the answer accordingly. One should not put extensions on commands. Especially not `.sh` when it's not even an sh script.

    @geirha Is this a reason to vote down? Go and inform yourself: or or;

    @geirha All I see here is a chatter which do not prove anything for me. Where it says there that the files with `.sh` extension do not denotes shell scripts?

    @RaduRădeanu, that's irrelevant. It's a bad idea to teach new scripters to put extensions on the commands they write. What language a command is written in is irrelevant. Do you care that `ls` is a compiled binary? would you care if it was a perl script? Do you care that `gunzip` is a bash script? And the links, with lovely animated ads, you point to even disagree with each other what `.sh` mean. One says it's a shell script, which is a very vague description (is `.sh` extension valid for csh scripts too?). The other says it's a self-extracting archive.

    @geirha Wake up! A file with `.sh` extension is primarily associated with a script designed to run at an UNIX/LINUX command prompt and finish. There is no problem if other kind of files have the same extension or if you don't want to use an extension for this type of file.

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM