Bash Shell Learning 01 (Configuration and startup scripts)

Source: Internet
Author: User
Tags aliases posix set set

Bash is Bourne Again shell abbreviation, developed from the UNIX system sh

View current Shell
Echo $SHELL
View system-supported shells
Cat/etc/shells

Cd/bin
Ls-la *sh

First, the bash shell configuration
Variables can be divided into custom variables and environment variables
They have different scopes.
Set can view all variables
Set|more View enter one line at a line
Set|less Enter newline PageDown page break Q exit

Env can only view environment variables

How bash shell is set up
1. Customize variable settings
Key=value
Like Aaa=ajax.
Echo $aaa to get Ajax
Variable names cannot start with numbers or special characters
Key1=test one key1= ' Test one ' and no spaces on 2 sides of the equals sign
Key2= "Key2 is $key 1" double quotes to parse
key1= ' KKK '
Key2= ' Kk2 '
key3= $key 1----$key 2
Echo $key 3
KKK----KK2
unset Key3 Delete a variable

Common variables
set|grep HIST
histfilesize: Record the maximum value saved by a history instruction
histsize: The number of displays when you perform a historical
COLUMNS: the width of the terminal window display
LINES: the height displayed by the terminal window
PS1: Set the content style before the cue symbol (\d,\ H,\T,\U,\W,\!,\$,\L, etc.)
\u Current user
\w Current working directory
\w current full working directory from/to
\h hostname
\ t Current time
\# login after the first few instructions
For example
ps1= ' [\[email protected]\h-\w-\t-\#] '
[[email protected]/var/var/lib-08:35:26-38]

2. Set by Alias (Aliases)
Settings, view all, view an alias value, Type-a, delete
Type LL
[Email Protected]/var/var/lib-08:35:26-38]type ll
LL is the alias of ' Ls-l--color=auto '
[[email protected] ~]# alias LL
Alias ll= ' Ls-l--color=auto '
[Email protected]/var/var/lib-08:35:43-39]type-a ls
LS is an alias of ' LS--color=auto '
[[Email Protected]/var/var/lib-08:35:45-40]type CD]
The CD is a shell embedded
View all aliases Alias
Set up
Alias cls= ' Clear '
[[Email Protected]/var/var/lib-08:42:55-51]type CLS
CLS is an alias of ' clear '
View alias's value alias CLS
[[Email Protected]/var/var/lib-08:43:00-52]alias CLS
Alias cls= ' Clear '
Delete alias definition
Unalias CLS

3. Set via SET command
Set itself to see the values of all variables
Set property values inside the shell (Set-o noclobber,set-o VI)
Ll>a.txt can write
Ll>a.txt can cover

Ll>a.txt
-bash:a.txt: Cannot overwrite an existing file
Ll>>a.txt can be appended
Set-o noclobber/* Set disable redirection override */
Set +o Noclobber/* Settings allow redirection overrides */
[[email protected] ~]# set-o
Allexport off
Braceexpand on
Emacs on
Errexit off
Errtrace off
functrace off
Hashall on
Histexpand on
history on
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
noexec off
Noglob off
Nolog off
Notify off
Nounset off
Onecmd off
Physical off
Pipefail off
POSIX off
Privileged off
verbose off
VI off
Xtrace off

[[Email protected] ~]# set +o
Set +o Allexport
Set-o Braceexpand
Set-o Emacs
Set +o Errexit
Set +o Errtrace
Set +o Functrace
Set-o Hashall
Set-o Histexpand
Set-o history
Set +o ignoreeof
Set-o interactive-comments
Set +o keyword
Set-o Monitor
Set +o Noclobber
Set +o noexec
Set +o Noglob
Set +o Nolog
Set +o Notify
Set +o Nounset
Set +o Onecmd
Set +o physical
Set +o Pipefail
Set +o POSIX
Set +o Privileged
Set +o verbose
Set +o VI
Set +o Xtrace

-o,+o
Set-o VI
Set the input command mode to VI
LS Press ESC to enter VIM command line mode edit state

4. Setting through environment variables
Custom variables are valid only in the current shell environment
Environment variables are valid in the shell environment under the entire host

You can use export variable name to set
Normal variable defined and promoted to environment variable by export variable name

If you reopen the connection session (root or admin login)
Key1,key2 are not.

Common variables:

PATH

Path= $PATH.:
Setting the hidden path to path poses a security issue?

[email protected] ~]# which CHGRP
/usr/bin/chgrp

[email protected] ~]# which LL
Alias ll= ' Ls-l--color=auto '
/usr/bin/ls

Second, shell startup scripts principle
Login and Non-login
Some scripts that are automatically executed when a user logs on or other non-logon actions
Creating a custom variable or executing a set set shell
Create environment variables, set other programs
Use alias to simplify subsequent operations
Which programs are executed at logon

Login
Full login Process
Execution execution/etc/profile (path/usr/hostname/histsize, etc.)
You can see it in the/etc/profile.
Read/etc/profile.d/*.sh (color language instruction alias)
~/.bash_profile,~/.bash_login,~/.profile (only one of them can be read sequentially)
~/.BASHRC (called in ~/.bash_profile),
/ETC/BASHRC (called in ~/.BASHRC)
Any one read succeeds and no longer reads the next
The respective home directories are only valid for each
After the modification succeeds, source reloads the script

Non-login
A shell that runs without logging in, such as a new bash action under Su and the original bssh
The script involved
~/.BASHRC and/ETC/BASHRC
/etc/profile.d/*.sh (color language directive alias)
Execute bash command

~/.bash_logout commands executed when the user logs off, backup, cleanup, etc.

Bash Shell Learning 01 (Configuration and startup scripts)

Related Article

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.