Shellexpand, a small library for shell-like expansions


I’m currently working on several applications in Rust, and since they need to work with files and be configurable, I really wanted to allow variables and home directory substitution for paths configured by the user in the config file. Sadly, Rust does not provide anything like os.Expand, so I decided to write a library for this myself.

And so I’ve just published shellexpand to This crate allows one to replace variable-like sequences ($A and ${A}) with values from the provided context, and it also provides functions to expand of ~ in the beginning of a string to a path to the home directory. Maybe it would be useful for someone else but me :slight_smile:

Links:, repository, documentation


A library like this would be useful for a project I’m working on :slight_smile: My project has a client and server setup that allows you to run commands on the remote server and receive the output on the local client. It directly executes the binary in order to avoid starting up a shell like popen does. The only downside is that there is no shell functionality since things like wildcards and pipes are all handled by the shell. Whenever I get a break from school I’ll probably take a better look at your library.



I needed exactly this functionality and spotted this crate yesterday. Nice work !
Since you are manipulating paths there, do you think it makes sense to return Cow<std::path::Path> instead of Cow<str> ?



The library is not only for working with paths, so I don’t think that using Cow<Path> would be appropriate. Variable replacement with some non-default context, for example, is not connected with paths at all :slight_smile: