export command in Limux

export command in Linux with Examples

The ‘export’ command is one of the essential built-in commands in the Bash shell, allowing users to manage environment variables effectively. It is defined in POSIX standards, which state that the shell will assign the export attribute to specified variables, causing them to be included in the environment of subsequently executed commands. Simply put, the export command makes environment variables available to child processes, enabling changes to be reflected immediately in the current shell session without needing to start a new session.

What is the ‘export’ Command?

In Bash, environment variables are set when you start a new shell session, and changes to these variables are not automatically picked up by the shell. The export command allows you to update and propagate the values of environment variables to the current session and any spawned child processes, ensuring that changes are immediately effective. This feature is crucial for tasks such as setting up paths, configuring environment-specific variables, or defining settings that multiple programs need to access.

Syntax:

export [-f] [-n] [name[=value] ...] or export -p

Options of ‘export’ command

1. Without any argument:

To view all the exported variables.

Example:

export_1

2. -p Option:

To view all exported variables on current shell.

Syntax:

$ export -p

Example:

export_2

3. -f Option:

It must be used if the names refer to functions. If -f is not used, the export will assume the names are variables.

Syntax:

$ export -f function_name

Example:

To export shell function:

export_3

Note: Bash command is used for showing that in the child shell, the shell function got exported.

4. name[=value]:

You can assign value before exporting using the following syntax.

Syntax:

$ export name[=value]

Example:

To set vim as a text editor

export_4

Note: No output will be seen on screen, to see exported variable grep from exported ones is used.

5. -n Option:

Named variables (or functions, with -f) will no longer be exported.

Syntax:

$ export -n variable_name

Example:

export_5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值