LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 06: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, 07:09 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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 07:18 AM.
 
Old 12-11-2011, 04: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:29 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