[email protected] and $* the difference
[Email protected]~] $vim my_fun.sh
#!/bin/bash
# [email protected] and $*
My_fun () {
echo "$#"
}
Echo ' The number of parameter in ' [email protected] ' is ' $ (my_fun "[email protected]")
Echo ' The number of parameter in [email protected] is ' $ (my_fun [email protected])
Echo ' The number of parameter in ' $* ' is ' $ (my_fun "$*")
Echo ' The number of parameter in $* ' $ (my_fun $*)
~
[[Email protected] ~]$ sh a.sh p1 "P2 P3" P4
The number of parameter in "[E-mail protected]" is 3
The number of parameter in [e-mail protected] is 4
The number of parameter in "$*" is 1
The number of parameter in $* is 4
Do you see the difference? key [email protected] be a little more reliable
2. About > and <
[email protected] ~]$ cat <file >file.bak
[email protected] ~]$ cat File;cat File.bak
This is a test
This is a test
[email protected] ~]$ cat <file >file
[[email protected] ~]$ cat file
[[email protected] ~]$ =====> This line of output is empty, the file has no content
Why can't I see the contents of the file in the last cat?
This is because the file is really an empty file at this point. Why???
Because in IO redirection, the standard output is prepared before it is read from the standard input to the standard output. is not a bit around.
It's like passing the baton in a relay race; you don't see the guy with the stick, you're definitely not going to send the baton out.
So, in the cat <file >file command, > will empty the file before it executes > files, and the result is empty.
3. How variables are evaluated in a for loop
A. Taking values from a set of strings
For Var in one, three four five
Do
Echo ****************************
Echo ' $var is ' $var
Done
B. Taking a value from a position variable
For Var;do
Do
Echo '-----------------------------'
Echo ' $var is ' $var
Done
C. Taking values from a cumulative change in format
#!/bin/bash
For ((var=1;var<=10;var++))
Do
Echo------------------------
Echo ' $var is ' $var
Done
D. Taking values from the command substitution
#!/bin/bash
For Var in $ (cat file.txt)
Do
Echo------------------------
Echo ' $var is ' $var
Done
This article is from the Linux OPS architect blog, so be sure to keep this source http://sharkyun.blog.51cto.com/10455795/1792976
Some easy-to-confuse concepts about shell scripting