Advantage of $Path Over Alias

Advantage of $PATH over alias

Putting python3 in your path is the correct way to invoke it anywhere you might find yourself in your filesystem. A symbolic link is the best way to change that command to python and keep your scripts non version dependent (you can run a script that depends on python use the symbolic link and a script that needs python 3.0 specifically use python3, even though on your computer they are the same thing). Symbolic links are still files in your filesystem, so they still need to be in your path.

I only see aliases used when you are trying to create some kind of behavior that is different than the default behavior for a command line utility like an alias for ls that adds -a silently.

Also symbolic links are stored in the filesystem so once created they exist for all other users who log in, while aliases only apply to the logged in user who has defined them. They can also have file permissions applied to them.

Here is a fun article about things you can do to your terminal through your .bash_profile including some great aliases.

What order does bash use to decide whether to use an alias, function, built-in, or executable?

What order does bash use to decide whether to use an alias, function, or executable?

Alias is not "executed". If aliases are enabled and when an alias matches then the word is replaced. Always.

Then, function first, executable second, if ordering these two.

Aliases are only expanded in interactive shells (not in scripts)

In bash, not really, just interactive shells have aliases enabled by default. You can enable aliases in non-interactive shells and disable in interactive shell - it's a separate property.

If a user-defined function has the same name as an executable, will bash run the function or the executable?

Function.

If a user-defined function has the same name as a bash built-in, will bash run the function or the built-in?

Function.

what is the order of precedence for what bash will run if there are two (or more) things with the same identifier?

The behavior is documented in bash documentation command search and execution. The behavior is standardized in POSIX Shell command language, section Command search and execution.

Modifying $PATH variable by a bash alias

Try to use a function instead:

changepath () {
export PATH="$JAVA_HOME/bin:$PATH";
}

In your case "$JAVA_HOME and $PATH are interpreted when you set the alias. So they are fixed to the moment when you execute the .bashrc.

With a function, variables will be interpreted at launching.

Note: I copy/paste you export PATH=..., but be careful you will add $PATH's content at every launch.

Get the `pwd` in an `alias`?

When your .zshrc is loaded, the alias command is evaluated. The command consists of two words: a command name (the builtin alias), and one argument, which is the result of expanding cleanup="rm -Rf `pwd`/{foo,bar,baz}". Since backquotes are interpolated between double quotes, this argument expands to cleanup=rm -Rf /home/unpluggd/{foo,bar,baz} (that's a single shell word) where /home/unpluggd is the current directory at that time.

If you want to avoid interpolation at the time the command is defined, use single quotes instead. This is almost always what you want for aliases.

alias cleanup='rm -Rf `pwd`/{foo,bar,baz}'

However this is needlessly complicated. You don't need `pwd/` in front of file names! Just write

alias cleanup='rm -Rf -- {foo,bar,baz}'

(the -- is needed if foo might begin with a -, to avoid its being parsed as an option to rm), which can be simplified since the braces are no longer needed:

alias cleanup='rm -Rf -- foo bar baz'

cygwin + $PATH + adding path to configuration

There are also another ways to do what you want. You don't have to add Notepad's directory to the PATH, when you need only one executable from that directory. The main advantage of a directory in the PATH is that every executable in that directory is available anywhere.

You can use for example alias, symbolic link or function. Each method creates the "npp" command, which you can then use as you suggested: npp filename. Advantage over the PATH method is that you can name it whatever you want.

alias

alias npp='/cygdrive/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe'

You can put it for example to your .bashrc. You can also add a parameters to an alias command. The name of an alias can be whatever you want.

symbolic link

ln -s /cygdrive/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe /usr/local/bin/npp

This will create a file in the directory /usr/local/bin which is already in your PATH. This file is symbolic link (something like Windows' shortcut) to the Notepad++ executable. The name of a symbolic link (the last part of the command) can be whatever you want, but you can't use a parameters there.

General format of the ln command for symbolic link:

ln -s target link_name

function

npp () {
/cygdrive/c/Program\ Files/Notepad++/notepad++.exe $(cygpath -w -- "$@")
}

Again, you can put it for example to your .bashrc and name it whatever you want. cygpath converts path to the file from Linux to the Windows format, but it should not be necessary.

Aliasing two different versions of the same program in linux?

If the program itself runs other programs from the bin directory, then when you run a version 1 program, you want to ensure that the version 1 directory is on the PATH ahead of the version 2 directory, and vice versa when you run a version 2 program. That is something I deal with all the time, and I deal with it by ensuring that the PATH is set appropriately.

In my $HOME/bin, I would place two scripts:

RunVersion1

 export PATH=/path/to/my/old/programs/bin:$PATH
# Set other environment variables as needed
exec runProgram "$@"

RunVersion2

 export PATH=/path/to/my/new/programs/bin:$PATH
# Set other environment variables as needed
exec runProgram "$@"

This technique of placing shell scripts on my PATH ahead of other programs allows me to pick which programs I run.

Semi-Generic Version

Often, I'll use a single program to set the environment and then link it to the various program names that I want to handle. It then looks at $0 and runs that:

 export PATH=/path/to/my/new/programs/bin:$PATH
# Set other environment variables as needed
exec $(basename $0 2) "$@"

If this script is linked to RunProgram2, the basename command lops off the 2 from the end of RunProgram2 and then executes RunProgram from the more recent directory.

I've used this general technique for accessing 32-bit and 64-bit versions of the software on a single machine, too. The programs I deal with tend to have more complex environments than just a setting of $PATH, so the scripts are bigger.

One of the main advantages of scripts in $HOME/bin over aliases and the like is that it doesn't much matter which shell I'm stuck with using; it works the same way. Plus I don't have so many places to look to find where the alias is defined (because it isn't defined).

JAX-RS: Multiple paths

yes you can do that although you will have to rename your methods so that their signature is different.

Update: Check Dieter Cailliau's answer, @Path("/{a:path1|path2}") is probably what you want...

public class BlahResource{
@GET
@Path("path1")
public Response m1(){
return Response.ok("blah").build();
}

@GET
@Path("path2")
public Response m2(){
return this.m1();
}

you can check JSR-311's API and it's reference implementation named "jersey" there:

JSR311 API

Jersey



Related Topics



Leave a reply



Submit