Linux shell Program, linuxshell

Source: Internet
Author: User

Linux shell Program, linuxshell

1. Check the number of shells we can use in Linux (centos6.5 as an example:

[root@localhost bin]# cat /etc/shells /bin/sh/bin/bash/sbin/nologin/bin/dash/bin/tcsh/bin/csh

Some services in the system will check the shells that users can use during operation, and the shell query is the file/etc/shells.

2. When we log on to the Linux system, the system will give me a shell to work, and the shell obtained by this login will be recorded in the/etc/passwd file:

[root@localhost bin]# cat /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologin...

3. shell internal command type, knowing that the command comes from external commands are built in bash.

[Root @ localhost bin] # man cd [root @ localhost bin] # type cdcd is a shell builtin [root @ localhost bin] # type-t cdBuiltin # indicates that this command is a built-in command function of bash.[Root @ localhost bin] # type-a cdcd is a shell builtin [root @ localhost bin] # type typetype is a shell builtin
[Root @ localhost bin] # type it ls
Alias #Indicates the name set by this command as the alias.

[Root @ localhost bin] # type uname
Uname is hashed (/bin/uname)
[Root @ localhost bin] # type-t uname
File #External commands

4. echo for variable access

[root@localhost bin]# echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin[root@localhost bin]# echo ${PATH}/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

Variable setting =. If a variable is not set, the content is blank.

[root@localhost bin]# echo $myname[root@localhost bin]# myname=tian[root@localhost bin]# echo $mynametian

The subroutine is to enable another new shell under the current shell, and the new shell is the subroutine. In general, the custom variables of the parent program cannot be used in the subroutine, but the variables can be applied in the subroutine by turning them into environment variables through export.

[Root @ localhost bin] # echo $ nameyes [root @ localhost bin] # bash # enter the so-called subroutine [root @ localhost bin] # echo $ name [root @ localhost bin] # exit # exit subroutine exit [root @ localhost bin] # export name [root @ localhost bin] # bash [root @ localhost bin] # echo $ nameyes [root @ localhost bin] # exit

Variable setting rules:

5. Environment Variables

Env, short for environment, lists all environment variables

[root@localhost /]# envHOSTNAME=localhost.localdomainSHELL=/bin/bashTERM=xtermHISTSIZE=1000USER=root...

Set, observe all variables (including environment variables and custom variables)

[root@localhost /]# envBASH=/bin/bashBASH_VERSINFO=([0]="4" [1]="1" [2]="2" [3]="1" [4]="release" [5]="i386-redhat-linux-gnu")BASH_VERSION='4.1.2(1)-release'HISTFILE=/root/.bash_historyHISTFILESIZE=1000HISTSIZE=1000HOSTTYPE=i386OLDPWD=/OSTYPE=linux-gnuPPID=5200PS1='[\u@\h \W]\$ '...

 

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.