8961 |
@table @code |
@table @code |
8962 |
@item CDPATH |
@item CDPATH |
8963 |
@evindex CDPATH |
@evindex CDPATH |
8964 |
When this variable is set @code{cd} is verbose, so idioms such as |
When this variable is set it specifies a list of directories to search |
8965 |
@samp{abs=`cd $rel && pwd`} break because @code{abs} receives the path |
when invoking @code{cd} with a relative filename. @acronym{POSIX} |
8966 |
twice. |
1003.1-2001 says that if a nonempty directory name from @code{CDPATH} |
8967 |
|
is used successfully, @code{cd} prints the resulting absolute |
8968 |
@c FIXME: Which shells? How do they behave? |
filename. Unfortunately this output can break idioms like |
8969 |
Setting @code{CDPATH} to the empty value is not enough for most shells. |
@samp{abs=`cd src && pwd`} because @code{abs} receives the path twice. |
8970 |
A simple path separator is enough except for @code{zsh}, which prefers a |
Also, many shells do not conform to this part of @acronym{POSIX}; for |
8971 |
leading dot: |
example, @command{zsh} prints the result only if a directory name |
8972 |
|
other than @file{.} was chosen from @code{CDPATH}. |
|
@example |
|
|
zsh-3.1.6$ @kbd{mkdir foo && (CDPATH=: cd foo)} |
|
|
/tmp/foo |
|
|
zsh-3.1.6$ @kbd{(CDPATH=:. cd foo)} |
|
|
/tmp/foo |
|
|
zsh-3.1.6$ @kbd{(CDPATH=.: cd foo)} |
|
|
zsh-3.1.6$ |
|
|
@end example |
|
|
|
|
|
@noindent |
|
|
(of course we could just @command{unset} @code{CDPATH}, since it also |
|
|
behaves properly if set to the empty string). |
|
8973 |
|
|
8974 |
Life wouldn't be so much fun if @command{bash} and @command{zsh} had the |
In practice the shells that have this problem also support |
8975 |
same behavior: |
@command{unset}, so you can work around the problem as follows: |
8976 |
|
|
8977 |
@example |
@example |
8978 |
bash-2.02$ @kbd{mkdir foo && (CDPATH=: cd foo)} |
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH |
|
bash-2.02$ @kbd{(CDPATH=:. cd foo)} |
|
|
bash-2.02$ @kbd{(CDPATH=.: cd foo)} |
|
|
/tmp/foo |
|
8979 |
@end example |
@end example |
8980 |
|
|
8981 |
Of course, even better style would be to use @code{PATH_SEPARATOR} instead |
Autoconf-generated scripts automatically unset @code{CDPATH} if |
8982 |
of a @samp{:}. |
possible, so you need not worry about this problem in those scripts. |
|
Therefore, a portable solution to neutralize @code{CDPATH} is |
|
|
|
|
|
@example |
|
|
CDPATH=$@{ZSH_VERSION+.@}$PATH_SEPARATOR |
|
|
@end example |
|
|
|
|
|
@noindent |
|
|
Note that since @command{zsh} supports @command{unset}, you may unset |
|
|
@code{CDPATH} using @code{PATH_SEPARATOR} as a fallback, see |
|
|
@ref{Limitations of Builtins}. |
|
8983 |
|
|
8984 |
@item IFS |
@item IFS |
8985 |
@evindex IFS |
@evindex IFS |
9120 |
sets @code{NULLCMD} to @samp{cat}. If you forgot to set @code{NULLCMD}, |
sets @code{NULLCMD} to @samp{cat}. If you forgot to set @code{NULLCMD}, |
9121 |
your script might be suspended waiting for data on its standard input. |
your script might be suspended waiting for data on its standard input. |
9122 |
|
|
9123 |
|
@item PWD |
9124 |
|
@acronym{POSIX} 1003.1-2001 requires that @command{cd} and |
9125 |
|
@command{pwd} must update the @env{PWD} environment variable to point |
9126 |
|
to the logical path to the current directory, but traditional shells |
9127 |
|
do not support this. This can cause confusion if one shell instance |
9128 |
|
maintains @env{PWD} but a subsidiary and different shell does not know |
9129 |
|
about @env{PWD} and executes @command{cd}; in this case @env{PWD} will |
9130 |
|
point to the wrong directory. Use @samp{`pwd`} rather than |
9131 |
|
@samp{$PWD}. |
9132 |
|
|
9133 |
@item status |
@item status |
9134 |
@evindex status |
@evindex status |
9135 |
This variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6), |
This variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6), |
9191 |
The use of @samp{break 2}, etcetera, is safe. |
The use of @samp{break 2}, etcetera, is safe. |
9192 |
|
|
9193 |
|
|
9194 |
|
@item @command{cd} and @command{pwd} |
9195 |
|
@c --------------------------------- |
9196 |
|
@prindex @command{cd} |
9197 |
|
@prindex @command{pwd} |
9198 |
|
@acronym{POSIX} 1003.1-2001 requires that @command{cd} and |
9199 |
|
@command{pwd} must support the @option{-L} and @option{-P} options, |
9200 |
|
with @option{-L} being the default. However, traditional shells do |
9201 |
|
not support these options, and their @command{cd} and @command{pwd} |
9202 |
|
commands have the @option{-P} behavior. |
9203 |
|
|
9204 |
|
Portable scripts should assume neither option is supported, and should |
9205 |
|
assume neither behavior is the default. This can be a bit tricky, |
9206 |
|
since the @acronym{POSIX} default behavior means that, for example, |
9207 |
|
@samp{ls ..} and @samp{cd ..} may refer to different directories. It |
9208 |
|
is safe to use @command{cd @var{dir}} if @var{dir} contains no |
9209 |
|
@file{..} components. Also, Autoconf-generated scripts check for this |
9210 |
|
problem when computing variables like @code{ac_top_srcdir} |
9211 |
|
(@pxref{Configuration Actions}), so it is safe to @command{cd} to |
9212 |
|
these variables. |
9213 |
|
|
9214 |
|
|
9215 |
@item @command{case} |
@item @command{case} |
9216 |
@c ----------------- |
@c ----------------- |
9217 |
@prindex @command{case} |
@prindex @command{case} |
9437 |
@end example |
@end example |
9438 |
|
|
9439 |
|
|
9440 |
|
@item @command{pwd} |
9441 |
|
@c ---------------- |
9442 |
|
See @command{cd} above. |
9443 |
|
|
9444 |
@item @command{set} |
@item @command{set} |
9445 |
@c ---------------- |
@c ---------------- |
9446 |
@prindex @command{set} |
@prindex @command{set} |
9654 |
@prindex @command{unset} |
@prindex @command{unset} |
9655 |
You cannot assume the support of @command{unset}, nevertheless, because |
You cannot assume the support of @command{unset}, nevertheless, because |
9656 |
it is extremely useful to disable embarrassing variables such as |
it is extremely useful to disable embarrassing variables such as |
9657 |
@code{CDPATH}, you can test for its existence and use |
@code{PS1}, you can test for its existence and use |
9658 |
it @emph{provided} you give a neutralizing value when @command{unset} is |
it @emph{provided} you give a neutralizing value when @command{unset} is |
9659 |
not supported: |
not supported: |
9660 |
|
|
9664 |
else |
else |
9665 |
unset=false |
unset=false |
9666 |
fi |
fi |
9667 |
$unset CDPATH || CDPATH=: |
$unset PS1 || PS1='$ ' |
9668 |
@end example |
@end example |
9669 |
|
|
9670 |
@xref{Special Shell Variables}, for some neutralizing values. Also, see |
@xref{Special Shell Variables}, for some neutralizing values. Also, see |