如何使用C语言代码在Linux中设置路径环境变量 [英] How to set path environment variable in linux in C language code

查看:692
本文介绍了如何使用C语言代码在Linux中设置路径环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过C程序在bash中设置路径环境变量. 因此,我使用"setenv"功能进行了编码,但这并不是解决问题的答案.

I want to set a path environment variable in bash by C program. So I coded using 'setenv' function, But it was not the answer to solve.

有人可以建议另一种方法来解决C编程问题吗?

Could anybody suggest another way to solve this problem in C programming?

我以为其他解决方案是程序先读取配置文件,然后进行修改并保存,但是实际上,当我打开该文件时,没有关于PATH变量的字符串.

I thought the other solution that the program read the profile file, then modify and save, but actually when I opened this file there's no string I wanted about PATH variable.

推荐答案

您可以使用setenv()putenv()设置环境变量.但是这些将仅针对给定的程序设置.您无法为外壳程序或其父进程设置环境变量.

You can use setenv() and putenv() to set environment variables. But these will only be set for the given program. You cannot set environment variables for the shell or its parent process.

这篇关于如何使用C语言代码在Linux中设置路径环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆