LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 12-10-2011, 07:41 AM   #1
origami-sheep
Member
 
Registered: Dec 2009
Distribution: Arch
Posts: 103

Rep: Reputation: 2
how to set my own commands?


hi all,

so running xmonad i like to be able to launch things direct from dmenu or a command prompt.

how would i set it up so that when i run, say, minecraft in the command prompt it runs the command java -jar /home/USER/Downloads/minecraft?

would i have to make a script in /bin? or is there anything else i should be doing?


thanks
 
Old 12-10-2011, 08:09 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Users' script are usually placed in the user home directory under $HOME/bin. This is not a rule, but many systems already include $HOME/bin in $PATH so that you can avoid to add it manually. On the other hand if you want to make your scripts available to other users, you should put them in a common location as /usr/local/bin.

In this particular case, since your command is a one-liner, you can simply define an alias
Code:
alias minecraft='java -jar /home/USER/Downloads/minecraft'
and put it in $HOME/.bashrc or $HOME/.alias (provided this last one is sourced by .bashrc as well). Another way to define custom commands is by means of shell functions.

Edit: sorry, I just noticed the /home/USER spec in your command line, so I guess this must be available to all users. In this case it would be better to put a script inside /usr/local/bin. If you want to change USER with the actual username, it should read
Code:
java -jar /home/$USER/Downloads/minecraft
In alternative you can define a function called minecraft, put its definition in a script under /etc/profile.d (the files inside it are sourced by /etc/profile) and export the function, e.g.
Code:
function minecraft {
  java -jar /home/$USER/Downloads/minecraft
}
export -f minecraft

Last edited by colucix; 12-10-2011 at 08:18 AM.
 
Old 12-11-2011, 05:50 AM   #3
origami-sheep
Member
 
Registered: Dec 2009
Distribution: Arch
Posts: 103

Original Poster
Rep: Reputation: 2
aaaahh alias >.<

completely forgot about that

thanks
 
  


Reply

Tags
command, launcher, xmonad


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to set redirect for all commands hillpigLQ Linux From Scratch 1 09-19-2008 01:27 PM
how to set redirect for all commands hillpigLQ Linux - Newbie 1 09-19-2008 06:51 AM
Set-up a network interface with commands?? helptonewbie Linux - Newbie 2 11-22-2007 05:45 AM
Etch Grub commands and set up Linux31 Debian 2 12-24-2006 06:36 AM
Setenv / set commands asaba Linux - Software 6 03-02-2005 05:35 AM


All times are GMT -5. The time now is 09:44 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration