Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Issue with resolving paths with zsh using \0 in variables

This is an issue found when attempting to use paths in zsh where parts of
the path are taken from data on the /sys filesystem. Namely, when cat'ing a
file from the /sys filesystem it may return some data with a \0 at the end.
If that variable is used to form a path the \0 interferes with the path
resolution. Here is an example of this:

root~# echo $ZSH_VERSION
root~# mkdir subdir
root~# printf "dir\0" > location
root~# touch subdir/myfile
root~# echo "hi" > sub$(cat location)/myfile
zsh: is a directory: subdir
root~# echo "hi" > subdir/myfile

It was found on bash that this did work, so it is believed that this is a
valid use case. Namely, on bash the \0 at the end of the data returned
from $(cat
location) is ignored.

There is a workaround for this, which is to use realpath on the directory
then use the result to access the file:

root~# complete=$(realpath sub$(cat location))
realpath: : No such file or directory
# ^ from stderr
root~# echo "hi" > ${complete}/myfile

However, it would be nicer if that workaround was not necessary.

If you have any questions about this issue, let me know. Thanks!

- Branden

Messages sorted by: Reverse Date, Date, Thread, Author