当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- scala 中 Future 的简单使用
- What details does C + + improve on the basis of C
- What is the difference between vivoy73s and vivoy70s
- C expression tree (1)
- 归纳一些比较好用的函数
- 盘点那些你没想到的云计算应用场景(上)
- Rust:命令行参数与环境变量操作
- Mate 40 series launch with Huawei sports health service to bring healthy digital life
- 抖音直播监控Api:随机推荐
- Windows下子系统Ubuntu安装
猜你喜欢
1.深入Istio:Sidecar自动注入如何实现的?
个人短网址生成平台 自定义域名、开启防红、统计访问量
技术人员该如何接手一个复杂的系统?
麦格理银行借助DataStax Enterprise (DSE) 驱动数字化转型
ASP.NET A complete solution based on exception handling in MVC
C language I blog assignment 03
蓝牙2.4G产品日本MIC认证的测试要求
python学习 day1——基础学习
NOIP 2012 提高组 复赛 第一天 第二题 国王游戏 game 数学推导 AC代码(高精度 低精度 乘 除 比较)+60代码(long long)+20分代码(全排列+深搜dfs)
软件测试就是这么回事?!
随机推荐
糟糕,系统又被攻击了
Do you really understand the high concurrency?
Bili Bili common API
Littlest JupyterHub| 02 使用nbgitpuller分发共享文件
Unparseable date: 'Mon Aug 15 11:24:39 CST 2016',时间格式转换异常
Review the cloud computing application scenarios you didn't expect (Part 1)
Seven features of Python 3.9
哔哩哔哩常用api
Summary of knowledge points of Jingtao project
Tiktok live monitoring Api: random recommendation
vivoy73s和荣耀30青春版的区别
C++在C的基础上改进了哪些细节
ASP.NET A complete solution based on exception handling in MVC
FORTRAN 77 reads some data from the file and uses the heron iteration formula to solve the problem
Brief history of computer
Cloud alibabab notes come out, the whole network detailed explanation only this one hand is slow
python学习 day1——基础学习
iOS 学习笔记二【cocopods安装使用和安装过程中遇到的问题及解决办法】【20160725更新】
How can a technician take over a complex system?
An error occurred while starting the kernel was successfully resolved