Shell: get started with Linux, OS X, and Unix Shell Environments

Source: Internet
Author: User

Shell: get started with Linux, OS X, and Unix Shell Environments

In Linux or Unix-like systems, each user and process runs in a specific environment. This environment contains variables, settings, aliases, functions, and more. The following is a brief introduction to some common commands in the Shell environment, including examples of how to use each command, and setting your own environment under the command line to improve efficiency.

Find your current shell

Enter any of the following commands in the terminal application:

  1. ps $$
  2. ps -p $$

Or

  1. echo "$0"

Output example:

Figure 1: Find the Current shell

Find all installed Shells

Find the complete path of the installed shell:

  1. type -a zsh
  2. type -a ksh
  3. type -a sh
  4. type -a bash

Output example:

Figure 2: Find the shell path

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

  1. cat /etc/shells

Output example:

  1. # List of acceptable shells for chpass(1).
  2. # Ftpd will not allow users to connect who are not using
  3. # one of these shells.
  4. /bin/bash
  5. /bin/csh
  6. /bin/ksh
  7. /bin/sh
  8. /bin/tcsh
  9. /bin/zsh
  10. /usr/local/bin/fish
Temporarily change the current shell

You only need to enter the shell Name. In the following example, I switched from bash to zsh:

  1. zsh

This only temporarily changes the system shell. It is also called a sub-shell. To exit from the child/Temporary shell, enter the following command or press the CTRL-D:

  1. exit
Find the sub-shell level or the nested level of the temporary shell

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

  1. echo "$SHLVL"

Sample output:

Figure 3: Bash shell nested hierarchy (number of sub-shells)

Use the chsh command to change the system shell permanently

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

  1. chsh -s /bin/zsh

Want to change the shell of another user from bash to ksh permanently? Try this:

  1. sudo chsh -s /bin/ksh userNameHere

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.