Ask Your Question

How do you pre-set preferences when starting a program?

asked 2015-07-23 23:06:06 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I want to run MATLAB, I have symbolic links set up so all I need to do is type:

$ matlab

for it to run. But I do not to run it using the desktop application and the java application. So I run it as

$ matlab -nodesktop -nojdw -nosplash

but for convenience I want to be able to run by just typing 'matlab.' How can I make this happen. I am fairly new to linux and my first guess would be to somehow include the options when I create the symbolic link but I am not sure how to format the syntax correctly. Fedora 22.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-24 00:48:31 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

You probably want to use bash aliases for this. They basically let you substitute a string for an arbitrary command. The string cannot have special characters that normally perform functions in it, but your command can have anything that would normally work in bash. They can be used in place of symlinks for what you were using those for, as well.

To create a temporary alias that will last until the end of the session (useful for experimentation):

alias my_alias_name="my_command"

If you think you might need to use the original, unaliased command in the future, you should name your alias something besides the original command name. Or, you can remove an alias until the session ends:

unalias my_alias_name

To make your alias permanent so that it will persist after exiting your session, you need to edit the .bashrc file in your home directory and add your alias to the end of the file:

nano ~/.bashrc

Scroll down to the end of the file and insert your aliases (under a new heading for clarity if you like), separated by newlines:

# Aliases #
alias my_alias_name_1="my_command_1"
alias my_alias_name_2="my_command_2"

Save the file with Ctrl+x (answer yes to "Save modified buffer" and overwrite the original if it exists). The aliases will be applied at your next login, or you can run the following:

source ~/.bashrc

That will initialize your aliases. If your command needs root, it's best to use su/sudo as usual after creating the alias instead of baking it into the command to be run. However, this will interfere with your aliases, since the shell only checks to see if the first part of a command is an alias, so it checks sudo, doesn't find an alias for it, and skips your intended aliases. To fix this, add another alias to your .bashrc:

alias sudo='sudo '

If the last character of a command executed by an alias is a whitespace character like tab or space, then bash will remember to keep checking the commands after it for aliases. That lets you run your aliases safely as root or a normal user.

If you want to make your life easier, instead of creating symlinks to executables, you can create aliases for them that include the path to the executable.

Hope that is useful!

edit flag offensive delete link more

Question Tools


Asked: 2015-07-23 23:06:06 -0500

Seen: 99 times

Last updated: Jul 24 '15