diff --git a/sources/tech/20190705 Manage your shell environment.md b/sources/tech/20190705 Manage your shell environment.md deleted file mode 100644 index c61ddc32f7..0000000000 --- a/sources/tech/20190705 Manage your shell environment.md +++ /dev/null @@ -1,121 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: (geekpi) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (Manage your shell environment) -[#]: via: (https://fedoramagazine.org/manage-your-shell-environment/) -[#]: author: (Eduard Lucena https://fedoramagazine.org/author/x3mboy/) - -Manage your shell environment -====== - -![][1] - -Some time ago, the Fedora Magazine has published an [article introducing ZSH][2] — an alternative shell to Fedora’s default, bash. This time, we’re going to look into customizing it to use it in a more effective way. All of the concepts shown in this article also work in other shells such as bash. - -### Alias - -Aliases are shortcuts for commands. This is useful for creating short commands for actions that are performed often, but require a long command that would take too much time to type. The syntax is: - -``` -$ alias yourAlias='complex command with arguments' -``` - -They don’t always need to be used for shortening long commands. Important is that you use them for tasks that you do often. An example could be: - -``` -$ alias dnfUpgrade='dnf -y upgrade' -``` - -That way, to do a system upgrade, I just type dnfUpgrade instead of the whole dnf command. - -The problem of setting aliases right in the console is that once the terminal session is closed, the alias would be lost. To set them permanently, resource files are used. - -### Resource Files - -Resource files (or rc files) are configuration files that are loaded per user in the beginning of a session or a process (when a new terminal window is opened, or a new program like vim is started). In the case of ZSH, the resource file is _.zshrc_, and for bash it’s _.bashrc_. - -To make the aliases permanent, you can either put them in your resource. You can edit your resource file with a text editor of your choice. This example uses vim: - -``` -$ vim $HOME/.zshrc -``` - -Or for bash: - -``` -$ vim $HOME/.bashrc -``` - -Note that the location of the resource file is specified relatively to a home directory — and that’s where ZSH (or bash) are going to look for the file by default for each user. - -Other option is to put your configuration in any other file, and then source it: - -``` -$ source /path/to/your/rc/file -``` - -Again, sourcing it right in your session will only apply it to the session, so to make it permanent, add the source command to your resource file. The advantage of having your source file in a different location is that you can source it any time. Or anywhere which is especially useful in shared environments. - -### Environment Variables - -Environment variables are values assigned to a specific name which can be then called in scripts and commands. They start with the $ dollar sign. One of the most common is $HOME that references the home directory. - -As the name suggests, environment variables are a part of your environment. Set a variable using the following syntax: - -``` -$ http_proxy="http://your.proxy" -``` - -And to make it an environment variable, export it with the following command: - -``` -$ export $http_proxy -``` - -To see all the environment variables that are currently set, use the _env_ command: - -``` -$ env -``` - -The command outputs all the variables available in your session. To demonstrate how to use them in a command, try running the following echo commands: - -``` -$ echo $PWD -/home/fedora -$ echo $USER -fedora -``` - -What happens here is variable expansion — the value stored in the variable is used in your command. - -Another useful variable is _$PATH_, that defines directories that your shell uses to look for binaries. - -### The $PATH variable - -There are many directories, or folders (the way they are called in graphical environments) that are important to the OS. Some directories are set to hold binaries you can use directly in your shell. And these directories are defined in the $PATH variable. - -``` -$ echo $PATH -/usr/lib64/qt-3.3/bin:/usr/share/Modules/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/usr/libexec/sdcc:/usr/libexec/sdcc:/usr/bin:/bin:/sbin:/usr/sbin:/opt/FortiClient -``` - -This will help you when you want to have your own binaries (or scripts) accessible in the shell. - --------------------------------------------------------------------------------- - -via: https://fedoramagazine.org/manage-your-shell-environment/ - -作者:[Eduard Lucena][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://fedoramagazine.org/author/x3mboy/ -[b]: https://github.com/lujun9972 -[1]: https://fedoramagazine.org/wp-content/uploads/2018/05/manage-shell-env-816x345.jpg -[2]: https://fedoramagazine.org/set-zsh-fedora-system/ diff --git a/translated/tech/20190705 Manage your shell environment.md b/translated/tech/20190705 Manage your shell environment.md new file mode 100644 index 0000000000..b3e7c5358f --- /dev/null +++ b/translated/tech/20190705 Manage your shell environment.md @@ -0,0 +1,122 @@ +[#]: collector: (lujun9972) +[#]: translator: (geekpi) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) +[#]: subject: (Manage your shell environment) +[#]: via: (https://fedoramagazine.org/manage-your-shell-environment/) +[#]: author: (Eduard Lucena https://fedoramagazine.org/author/x3mboy/) + +管理你的 shell 环境 +====== + +![][1] + +段时间,Fedora Magazine 发表了一篇 [ZSH 介绍][2]的文章,它是 Fedora 默认的 bash shell 的替代。这一次,我们将着重定制它来更有效地使用它。本文中显示的所有概念也适用于其他 shell,例如 bash。 + +### 别名 + +别名是命令的快捷方式。为那些需要经常执行,但需要很长时间输入的长命令创建快捷方式很有用。语法是: + +``` +$ alias yourAlias='complex command with arguments' +``` + +它们并不总是用来缩短长命令。重要的是,你将它们用于你经常执行的任务。可能的例子: + + +``` +$ alias dnfUpgrade='dnf -y upgrade' +``` + +这样,为了进行系统升级,我只需输入 dnfUpgrade 而不用输入完整的 dnf 命令。 + +在终端中设置别名的问题是,一旦终端会话关闭,别名就会丢失。要永久设置它们,请使用资源文件。 + +### 资源文件 + +资源文件(或 rc 文件)是在会话或进程开始时(每个用户在开启新终端窗口或启动 vim 等新程序时)加载的配置文件。对于 ZSH,资源文件是 _.zshrc_,对于 bash,它是 _.bashrc_。 + +要使别名成为永久别名,你可以将它们放入资源中。你可以使用你选择的文本编辑器编辑资源文件。这里使用 vim: + +``` +$ vim $HOME/.zshrc +``` + +或者对于 bash: + +``` +$ vim $HOME/.bashrc +``` + +请注意,资源文件的位置是相对于家目录指定的。这是 ZSH(或 bash)默认为每个用户查找文件的位置。 + +还有一种是将你的配置放在任何其他文件中,然后读取它: + +``` +$ source /path/to/your/rc/file +``` + +同样,在会话中直接读取它只会将其应用于会话,因此要使其永久化,请将 source 命令添加到资源文件中。将文件放在不同位置的优点是你可以随时读取它。这在共享环境中很有用。 + +### 环境变量 + +环境变量是分配给特定名称的值,你可以在脚本和命令中调用它们。它们以美元符号开始。其中最常见的是引用主目录的 $HOME。 + +顾名思义,环境变量是你环境的一部分。使用以下语法设置变量: + +``` +$ http_proxy="http://your.proxy" +``` + +要使其成为环境变量,请使用以下命令将其导出: + +``` +$ export $http_proxy +``` + +要查看当前设置的所有环境变量,请使用 _env_ 命令: + +``` +$ env +``` + +该命令输出会话中可用的所有变量。要演示如何在命令中使用它们,请尝试运行以下 echo 命令: + +``` +$ echo $PWD +/home/fedora +$ echo $USER +fedora +``` + +这里发生了变量扩展,即存储在变量中的值在命令中使用。 + +另一个有用的变量是 _$PATH_,它定义了 shell 查找二进制文件的目录。 + +### $PATH 变量 + +有许多对于操作系统很重要的目录或文件夹(在图形环境中调用它们的方式)。某些目录设置为保存可直接在 shell 中使用的二进制文件。这些目录在 $PATH 变量中定义。 + +``` +$ echo $PATH +/usr/lib64/qt-3.3/bin:/usr/share/Modules/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/usr/libexec/sdcc:/usr/libexec/sdcc:/usr/bin:/bin:/sbin:/usr/sbin:/opt/FortiClient +``` + +当你希望在 shell 中访问自己的二进制文件(或脚本)时,这会有帮助。 + +-------------------------------------------------------------------------------- + +via: https://fedoramagazine.org/manage-your-shell-environment/ + +作者:[Eduard Lucena][a] +选题:[lujun9972][b] +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://fedoramagazine.org/author/x3mboy/ +[b]: https://github.com/lujun9972 +[1]: https://fedoramagazine.org/wp-content/uploads/2018/05/manage-shell-env-816x345.jpg +[2]: https://fedoramagazine.org/set-zsh-fedora-system/