本文主要是介绍Seeing The World As The Shell Sees It,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Here we will introduce one command:
echo:display a line of text
Expansion
For example “*”,can have a lot of meaning to the shell.The process that makes this happen is called expansion.
echo
echo is a shell built that performs a very simple task.example:
echo this is a text
echo *
can’t print ““,in privious character means match any characters in a filename.The shell expanse the “*” into something else before the echo command is executed.When the enter key is pressed,the shell expands any qualifying characters on the command line before the command is carried out.example:
echo [[:upper:]]*
## will show all the file that beginning with an upper character
echo /usr/*/share
## "*" expanse everything you can image~
want to expanse hiden file?,OK:
echo .*
but this command will show ‘.’ and ‘..’ this two.If I don’t want show current directory and parent directory,I can try:
echo .[!.]*
this will work correctly in most files.It still can’t include filenames with multiple leading periods,so if you want to show a correct listing of hidden files:
ls -A
Tilde Expansion
the ~ character means the home directory of the current user:
echo ~
if user ‘wuxiao’ has an account,then:
echo ~wuxiao
## it is the same of 'echo ~' with 'wuxiao' user
Arithmetic Expansion
we can use the shell prompt as a calculator
echo $((2+2))
Arithmetic expansion use the form:
$((expression))
Arithmetic operators:
- +
- -
- *
- /
- ** :Exponentiation
example:
echo $(($((5**2))*3))
echo $((5**2*3))
echo $(((5**2)*3))
##output is 75
echo ((5/2))
##will display 2
Brace expansion
with brace,you can create multiple text strings from a pattern containing braces,example:
echo Front - {A,B,C} - Back
## will show 'Front - {A,B,C} - Back'
using a range of integers:
echo Number_{1..5}
##will show Number_1 Number_2 ... Number_5
also can be zero-padded like:
echo {001..6}
##001 002 003 ... 006
echo {z..a}
##z y x ... a
The most common application is to make lists of files or directories to be created:
mkdir {2015..2017}-{01..12}
Parameter expansion
Use variable to store small chunks of data and to give each chunk a name.
echo $USER
printenv | less
echo $(ls)
Quoting
echo this is a test
##this is a test
echo the total is $100.00
##the total is 00.00
Shell will remove the extra whitespace from the echo command’s arguments.example 2 shell will treat ‘$1’ as a parameter expasion.SO what should we do if we want to leave the origin output?
Use Double Quotes
ls -l "two words.txt"
mv "two words.txt" two_words.txt
echo "$USER "\$100.00" $(cal)"
Single Quotes
If we need to suppress all expansions,we use single quotes:
echo '23467567*&!~@$%}{}|?/\6346'
Escaping Characters ‘\’
Just like the function in C.Here are some frequent examples:
- \a:Bell
- \b:Backspace
- \n:NewLine
- \r:Carriage return
- \t:Tab
这篇关于Seeing The World As The Shell Sees It的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!