当前位置:网站首页>Rust: command line parameter and environment variable operation
Rust: command line parameter and environment variable operation
2020-11-08 08:59:00 【osc_sejgcp0】
Rust in , We often encounter command line parameters and environment variable operations . Let's have a look at .
One 、 Command line arguments

You can see from above ,std::env Realized from cargo run Command line parameters are extracted from the command line a b c Enter the program .
Two 、 Read environment variables
std::env::var function , The function of environment variable in operating system is realized .
env::var()-> std::env::Vars
Vars What is it? , Very complicated , He did Iterator. The following is the source code in the standard library :
#[stable(feature = "env", since = "1.0.0")]
pub struct Vars {
inner: VarsOs,
}
/// An iterator over a snapshot of the environment variables of this process.
///
/// This structure is created by the [`std::env::vars_os`] function. See
/// its documentation for more.
///
/// [`std::env::vars_os`]: vars_os
#[stable(feature = "env", since = "1.0.0")]
pub struct VarsOs {
inner: os_imp::Env,
}
It should be noted that , In the environment variables , Characters don't have to be Unicode The standard , That would be a false report . You can use :
env::vars_os
following : Read specific environment variables
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
//println!("get command args :{:?} ", args);
//println!("get env args : ");
for (key, value) in env::vars() {
//println!(" {} => {}", key, value);
}
let key = "PATH";
match env::var(key) {
Ok(val) => {
// val is String, splited by ";"
println!("val =>{}",val);
},
Err(e) => println!("couldn't interpret {}: {}", key, e),
}
}
3、 ... and 、 Set the environment variable
Generally include : View all environment variables 、 Set new environment variables and modify old environment variables .
1、 stay cmd Next


The settings are made above , View individual environment variable operations 、 Modify the operating . It's still relatively simple .
2、powshell
# View all environment variables ls env:
# Search for environment variables ls env:NODE*
# Look at a single environment variable $env:NODE_ENV
# add to / Update environment variables $env:NODE_ENV=development
# Delete environment variables del evn:NODE_ENV
3、linux
modify bashrc file , This method is safer , It can control the permission to use these environment variables to the user level , This is for a specific user , If you need to give a user permission to use these environment variables , You only need to modify the
.bashrc Just file it .vi ~/.bashrc
Add below :
Export PATH="$PATH:/NEW_PATH"
source :
https://www.cnblogs.com/Joans/p/7760378.html
版权声明
本文为[osc_sejgcp0]所创,转载请带上原文链接,感谢
边栏推荐
- Oschina plays on Sunday - before that, I always thought I was a
- laravel8更新之速率限制改进
- OSChina 周日乱弹 —— 之前呢,我一直以为自己是个……
- An error occurred while starting the kernel was successfully resolved
- 狗狗也能操作无人机!你没看错,不过这其实是架自动驾驶无人机 - 知乎
- Which is more worth starting with the difference between vivos7e and vivos7
- 架构师(2020年11月)
- Mouse small hand
- Windows subsystem Ubuntu installation
- Astra: the future of Apache Cassandra is cloud native
猜你喜欢

0.计算机简史

Qt混合Python开发技术:Python介绍、混合过程和Demo

sed之查找替换

Improvement of rate limit for laravel8 update

蓝牙2.4G产品日本MIC认证的测试要求

Which is more worth starting with the difference between vivos7e and vivos7

盘点那些你没想到的云计算应用场景(上)

swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案

Ulab 1.0.0 release

Application of bidirectional LSTM in outlier detection of time series
随机推荐
Cloud Alibabab笔记问世,全网详解仅此一份手慢无
413【毕设课设】基于51单片机无线zigbee无线智能家居光照温湿度传输监测系统
Adobe Prelude / PL 2020 software installation package (with installation tutorial)
QT hybrid Python development technology: Python introduction, hybrid process and demo
ubuntu实时显示cpu、内存占用率
ASP.NET MVC下基于异常处理的完整解决方案
vivoS7e和vivoS7的区别 哪个更值得入手
Blazor 准备好为企业服务了吗?
微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!
2020-11-05
技术人员该如何接手一个复杂的系统?
5g/4g工业无线路由器
软件测试就是这么回事?!
架构师(2020年11月)
Macquarie Bank drives digital transformation with datastex enterprise (DSE)
Which is more worth starting with the difference between vivos7e and vivos7
golang 匿名结构体成员,具名结构体成员,继承,组合
函数周期表丨筛选丨值丨SELECTEDVALUE - 知乎
OSChina 周日乱弹 —— 之前呢,我一直以为自己是个……
swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案