LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to set my own commands? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-set-my-own-commands-918027/)

origami-sheep 12-10-2011 06:41 AM

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

colucix 12-10-2011 07:09 AM

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


origami-sheep 12-11-2011 04:50 AM

aaaahh alias >.<

completely forgot about that

thanks :)


All times are GMT -5. The time now is 12:54 AM.