LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 07-03-2014, 12:40 PM   #1
lapishater276
Member
 
Registered: Jun 2014
Location: Narnia
Distribution: Crunchbang, Arch Linux ARM, Xubuntu
Posts: 43

Rep: Reputation: 0
how would i make a shell script into a command?


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.
 
Old 07-03-2014, 12:47 PM   #2
Hungry ghost
Senior Member
 
Registered: Dec 2004
Posts: 1,222

Rep: Reputation: 667Reputation: 667Reputation: 667Reputation: 667Reputation: 667Reputation: 667
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).
 
Old 07-03-2014, 01:03 PM   #3
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware
Posts: 441

Rep: Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574
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
 
1 members found this post helpful.
Old 07-03-2014, 06:58 PM   #4
Hungry ghost
Senior Member
 
Registered: Dec 2004
Posts: 1,222

Rep: Reputation: 667Reputation: 667Reputation: 667Reputation: 667Reputation: 667Reputation: 667
Since this is now marked as solved I guess it worked? In that case, you're welcome...
 
1 members found this post helpful.
Old 07-17-2014, 08:21 PM   #5
the dsc
Member
 
Registered: May 2009
Distribution: Debian
Posts: 175
Blog Entries: 243

Rep: Reputation: 47
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.

Last edited by the dsc; 07-17-2014 at 08:23 PM.
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] can`t make make with the provided shell script. funky445o Linux - General 8 06-03-2013 04:45 PM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
[SOLVED] How to make several "renames" by inoking a single command? Make a shell script file? Foxbat1155 Linux - Newbie 20 11-25-2011 09:13 AM
Using shell command output as input in shell script - how to do? EnderX Linux - Newbie 2 06-30-2010 12:46 PM
How to make system(command) to runinside a shell script? AviMittal Linux - Newbie 5 05-26-2009 05:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 07:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration