Bash Shell programming Exercises

Source: Internet
Author: User

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

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.