[SOLVED] how would i make a shell script into a command?
DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i am trying to create a shell script that can be used as a command in the bash terminal. the script compresses files, and the command is to be called compressor. how would i do this?
UPDATE: the problem has been solved. thanks to everyone who helped
Last edited by lapishater276; 07-04-2014 at 09:12 AM.
You could name the script any name you desire ('compressor', in this case), and put it inside say /home/<user>/bin (or /usr/local/bin, if you want it to be available by every user in your system). Then you'd simply need to call the script from the CLI like you do with any other command (provided the directory you used to store it is in your path).
Either copy the script file in one of the directories included in the '$PATH' environment variable (do 'echo $PATH' in order to see them), or add to '$PATH' the directory where the file itself is located. '$PATH' is usually defined system-wide in '/etc/profile', or in '~/.bashrc' at a user's level. Finally, make your script executable with 'chmod +x <path-to-script>/compressor'. That's it.
Last edited by Philip Lacroix; 07-03-2014 at 01:09 PM.
Reason: script name as in OP
If one doesn't want for some reason to add more folders to the PATH variable, it still can be achieved by an alias that includes the path in the command.
alias myscriptcommand='/whatever/path/I/dont/want/to/be/part/of/PATH/myscript.sh even-parameter-if-applies'
And that line goes into something like .bashrc or something similar, wherever one prefer to have aliases working.
But unlike having it on PATH, the "command" won't work from within other scripts, only from a terminal session.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.