shell - 如何使用 entr 在保存时编译和运行 Rust 文件?

标签 shell rust

我如何使用 entr在每次保存时自动编译和运行测试 Rust 文件?我试过了

ls test.rs | entr -c "rustc test.rs && ./test"

但它给出了错误:

entr: exec rustc test.rs && ./test: No such file or directory

最佳答案

您需要 -s 参数,它使用您的 shell 来评估命令:

-s  Evaluate the first argument using the
    interpreter specified by the SHELL
    environment variable.  When this flag
    is set, the name of the shell and exit
    code is printed after each invocation.

正确的命令是:

ls test.rs | entr -cs "rustc test.rs && ./test"

作为奖励,它还会为每次调用打印退出代码!

Hello World!
zsh returned exit code 0

与 cargo 类似,在 src 目录下保存的任何 rust 文件更改:

ls src/**/*.rs | entr -cs "cargo run"

关于shell - 如何使用 entr 在保存时编译和运行 Rust 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55432460/

相关文章:

linux - 如何同时在多个选项卡/shell 中运行相同的 linux 命令?

linux - 在 Bash 中,如何显示脚本输出然后恢复到之前的输出(如 less、top 或 watch)

mysql - 从文件读入变量 - Bash Script take2

reference - 如何从 for 循环中检索用户定义的类型?

rust - Polars Dataframe-基于一列删除重复行

rust - Result<usize, std::io::error::Error> 在 Rust 1.0.0 中没有实现 expect

bash - 从文本表中提取 URL(多行)

linux - 使用 bash 将一个 txt 文件复制两次到另一个文件

rust - struct 字段中 Rng 的 Vec,不能借用不可变字段作为可变字段

reference - 可以实现返回引用或拥有值的特征方法