1. Create the executable file t2.sh and print "Hello world!"
[Email protected] ~~ $ cd tscripts/'#!/bin/bash' >>' echo "Hello world!" ' >>~/tscripts $ chmod +x *~/tscripts $./t2.sh Helloworld!
2. Methods to run the executable file in 3
[Email protected] ~/tscripts $./t2.sh Helloworld! ~/tscripts $ sh t2.sh helloworld! ~/tscripts $/bin/sh t2.sh helloworld!
3. Using variables
[Email protected] ~/tscripts $ name=~/~/
Curly braces outside the variable name are optional and can be added without adding curly braces to help the interpreter identify the bounds of the variable
4. For loop print Java C C + + PHP Scala, experience the role of ${}
#!/bin/Bash forSkillinchJava c C + + PHP Scala; DoEcho"I am good at $skill"Done Echo"=======================================" forSkillinchJava c C + + PHP Scala; DoEcho"I am good at $skillScript"Done Echo"=======================================" forSkillinchJava c C + + PHP Scala; DoEcho"I am good at ${skill}script" Done
5. Read-only variables, unset cannot be canceled
[Email protected] ~/tscripts $ name=readonly~/~/tscripts $ name=Tom ReadOnly~/tscripts $ unset namereadonly
6. Non-read-only variable can be canceled, cancel print to empty
[Email protected] ~/tscripts $ unname=~/~/tscripts $ echo $unname
7. Single quotation marks
~ $ name='Leo'$name ' $'name'
8. Double quotes
" I am $name " "\\i am $name \ \"\i am Leo \
9. Stitching strings
" He is $name " is "$name is handsome"! is handsome! "$name is handsome! "-bash:! " : Event not found
10. Get the string length
[Email protected] ~ $ echo ${#name}3
11. Extracting A String
[Email protected] ~ $ echo ${name:0:2}le
12.
Bash Shell programming Exercises