6 releases (stable)

Uses old Rust 2015

2.1.0 Dec 22, 2020
2.0.0 Feb 20, 2020
1.1.1 Jan 2, 2020
1.1.0 Dec 21, 2019
0.1.0 Mar 13, 2016

#7 in Compression

Download history 10477/week @ 2020-10-02 8745/week @ 2020-10-09 9205/week @ 2020-10-16 11172/week @ 2020-10-23 11633/week @ 2020-10-30 9987/week @ 2020-11-06 8385/week @ 2020-11-13 8276/week @ 2020-11-20 9247/week @ 2020-11-27 9553/week @ 2020-12-04 10728/week @ 2020-12-11 7415/week @ 2020-12-18 6075/week @ 2020-12-25 10205/week @ 2021-01-01 12387/week @ 2021-01-08 7990/week @ 2021-01-15

40,586 downloads per month
Used in 141 crates (93 directly)


452 lines

shellexpand, a library for shell-like expansion in strings

Build Status crates.io docs


shellexpand is a single dependency library which allows one to perform shell-like expansions in strings, that is, to expand variables like $A or ${B} into their values inside some context and to expand ~ in the beginning of a string into the home directory (again, inside some context).

This crate provides generic functions which accept arbitrary contexts as well as default, system-based functions which perform expansions using the system-wide context (represented by functions from std::env module and dirs crate).

Note: because I no longer have capacity to support it, I'm now looking for a new maintainer for this library. Until I'm able to find one, it is unlikely to receive new updates in any reasonably timely manner.


Just add a dependency in your Cargo.toml:

shellexpand = "2.1"

See the crate documentation (a link is present in the beginning of this readme) for more information and examples.


Version 2.1.0

  • Switched to dirs-next instead of the obsolete dirs as the underlying dependency used to resolve the home directory
  • Switched to GitHub Actions instead of Travis CI for building the project.

Version 2.0.0

  • Added support for default values in variable expansion (i.e. ${ANSWER:-42})
  • Breaking changes (minimum Rust version is now 1.30.0):
    • Using dyn for trait objects to fix deprecation warning
    • Switched to using source() instead of cause() in the Error implementation, and therefore added a 'static bound for the generic error parameter E

Version 1.1.1

  • Bump dirs dependency to 2.0.

Version 1.1.0

  • Changed use of deprecated std::env::home_dir to the dirs::home_dir function

Version 1.0.0

  • Fixed typos and minor incompletenesses in the documentation
  • Changed home_dir argument type for tilde expansion functions to FnOnce instead FnMut
  • Changed LookupError::name field name to var_name

Version 0.1.0

  • Initial release


This program is licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.