Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to master the Shell environment of Linux,OS XMagi Unix

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to master the Shell environment of Linux,OS XMagi Unix". In the daily operation, I believe many people have doubts about how to master the Shell environment of Linux,OS XMagi Unix. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to master the Shell environment of Linux,OS XMagi Unix". Next, please follow the editor to study!

Find out your current shell

Enter any of the following commands in the terminal application:

Ps $$ps-p $$

Or

Echo "$0"

Sample output:

Figure 1: find the current shell

Find all installed shell

Find the full path to the installed shell:

Type-a zshtype-a kshtype-a shtype-a bash

Sample output:

Figure 2: find the path to shell

The file / etc/shells contains a list of shell supported by the system. Each line represents a shell, which is the full path relative to the root directory. Use this cat command to view the data:

Cat / etc/shells

Sample output:

# List of acceptable shells for chpass (1). # Ftpd will not allow users to connect who are not using# one of these shells. / bin/bash/bin/csh/bin/ksh/bin/sh/bin/tcsh/bin/zsh/usr/local/bin/fish temporarily changes the current shell

Just enter the name of shell. In the following example, I switched from bash to zsh:

Zsh

This is only a temporary change to the system shell. Also known as son shell. To exit from a child / temporary shell, enter the following command or press CTRL-D:

Exit finds the level of child shell or the nesting level of temporary shell

After each bash instance is started, the value of the variable $SHLVL is incremented. Enter the following command:

Echo "$SHLVL"

Sample output:

Figure 3:Bash shell nesting level (number of child shell)

Permanently change the system shell through the chsh command

Want to permanently change the current system shell from bash to zsh? Try this:

Chsh-s / bin/zsh

Want to permanently change the shell of other users from bash to ksh? Try this:

Sudo chsh-s / bin/ksh userNameHere view current environment variables

You need to use:

Envenv | moreenv | lessenv | grep 'NAME'

Sample output:

TERM_PROGRAM=Apple_TerminalSHELL=/bin/bashTERM=xterm-256colorTMPDIR=/var/folders/6x/45252d6j1lqbtyy_xt62h50c0000gn/T/Apple_PubSub_Socket_Render=/tmp/launch-djaOJg/RenderTERM_PROGRAM_VERSION=326TERM_SESSION_ID=16F470E3-501C-498E-B315-D70E538DA825USER=vivekSSH_AUTH_SOCK=/tmp/launch-uQGJ2h/Listeners__CF_USER_TEXT_ENCODING=0x1F5:0:0PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/go/bin:/ Usr/local/sbin/modemZapp:/Users/vivek/google-cloud-sdk/bin__CHECKFIX1436934=1PWD=/Users/vivekSHLVL=2HOME=/Users/vivekLOGNAME=vivekLC_CTYPE=UTF-8DISPLAY=/tmp/launch-6hNAhh/org.macosforge.xquartz:0_=/usr/bin/envOLDPWD=/Users/vivek

Here is a list of some common variables in bash shell:

Figure 4: common bash environment variables

Note: the following environment variables are fine and do not change. It is likely to cause unstable shell sessions:

SHELL

UID

RANDOM

PWD

PPID

SSHAUTHSOCK

USER

HOME

LINENO

Display the value of the environment variable

Use any of the following commands to display the value of the environment variable HOME:

# # using printenv # # printenv HOME # # or using echo # # echo "$HOME" # for portability, you can also use printf # # printf "% s\ n"$HOME"

Sample output:

/ home/vivek adds or sets a new environment variable

Here is the syntax for bash,zsh,sh and ksh:

# # Syntax # # VAR=valueFOO=bar # # set vim as the default text editor # # EDITOR=vimexport $EDITOR # # consider security, set the default shell connection timeout # # TMOUT=300export TMOUT # # you can directly use the export command to set the search path of the command # # export PATH=$PATH:$HOME/bin:/usr/local/bin:/path/to/mycoolapps

Then, use the printenv or echo or printf commands to view the values of the environment variables PATH,EDITOR, and TMOUT:

How does printenv PATHecho "$EDITOR" printf "% s\ n" $TMOUT modify an existing environment variable?

Here is the syntax:

Export VAR=value## or # # VAR=valueexport $VAR # # change the default text editor from vim to emacs # # echo "$EDITOR" # #

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report