That's not the Bourne shell, or bash
emulating the Bourne shell, that's the Almquist shell, in your case probably the Debian Almquist shell (a Linux fork by Debian of BSDs' sh itself based on the original Almquist shell).
In the Almquist shell (the original one and the modern versions), %
is used in PATH
for extra features specific to ash
. Quoting from the documentation:
Path Search
When locating a command, the shell first looks to see if it has a shell
function by that name. Then, if PATH does not contain an entry for
%builtin
, it looks for a builtin command by that name. Finally, it
searches each entry in PATH in turn for the command.
The value of the PATH variable should be a series of entries separated by
colons. Each entry consists of a directory name, or a directory name
followed by a flag beginning with a percent sign. The current directory
should be indicated by an empty directory name.
If no percent sign is present, then the entry causes the shell to search
for the command in the specified directory. If the flag is %builtin
then the list of shell builtin commands is searched. If the flag is
%func
then the directory is searched for a file which is read as
input to the shell. This file should define a function whose name is the
name of the command being searched for.
Command names containing a slash are simply executed without performing
any of the above searches.
Other shells like ksh
or zsh
have a similar autoloading of functions mechanism, but they use a different variable ($FPATH
), but you can't define which of functions or executables take precedence.
In your case, /home/torbjorr/deployed/vector/x86_64-GNU%2fLinux
is interpreted as the /home/torbjorr/deployed/vector/x86_64-GNU
directory with the 2fLinux
flag. That flag is ignored as it is unknown.
There is no way around that. Even if ash had an escape mechanism so that this %
not be treated specially, it would then not work in other shells or other things that look up $PATH
like execvp()
.
You'll need to remove the %
characters from $PATH
, so rename your directory or add a symlink.
Or don't use ash
for your /bin/sh
. Other lightweight POSIX shell implementations that don't do that include yash
and mksh
.
The alias actually seems to work for me like that (provided that there's no whitespace after the backslashes). But a function might be nicer and at least makes it easier to use single-quotes:
staging_server() {
MY_ENV1='http://example.com' \
MY_ENV2="..." \
start_server -p 1234 "$@"
}
Best Answer
You can do:
Each subsequent line appends onto the previously defined path. This is generally a good habit, as it avoids trashing the existing path. If you want the new component to take precedence, swap the order:
Alternatively, you might be able to do:
where
\
marks a line continuation. Haven't tested this method.