We need to know a little shell script.

Source: Internet
Author: User

Most of the time you don't have to write your own, but see if you can read it together and see an example of less than 10 lines.

#!bin/bashgetcontent () {if [!-e $]; then return 1;fi content= ' cat $ ' echo ${content//root/h2do}}getcontent/etc/h 2doecho $?getcontent/etc/passwd

Line 1th: Select Bash to interpret subsequent scripts;

Line 2nd: function declaration;

Line 3rd: The reserved variable is used to represent the first parameter, the first parameter is the file path, determine whether the file exists, if there is no function directly return;

Line 4th: Use the cat command to store the contents of the file in variable content;

Line 5th: Output the content variable, while replacing all the root in the contents with h2do by regular, the variable is replaced by one/time only once, two//replace all;

Line 7th: Function call, use a nonexistent file;

Line 8th: Output the previous command to return the result;

Line 9th: Function call, use an existing file;


We need to know a little shell script.

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.