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?

1 Answer

Your script should look like:

#!/bin/bash
passwd

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

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

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

./password.sh #or ./password

or

/path/to/password.sh #or /path/to/password

To run it only using:

password.sh #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.

10

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like