[Shell] Implements script execution results matching a string

Source: Internet
Author: User

Today I received a request that a string be included in the result of the script execution and asked to find out.

The idea I gave was to write the text in an appended way according to the name of the script and the result, and then find the corresponding content from the text.

The other side of the train of thought is to execute the results to judge, on their own to achieve this way

The first is to write the script according to the directory, here is the content of the Echo $i written in the script. That is, the script has execution results.

#!/bin/Bashsh_dir=sh_dircd $SH _dir for in $ (seq);  do        Echo " Echo $i "> $i.sh done

Then the loop executes and looks for the script, which is all traversed once and can be done by itself only to find the first one to terminate.

1#!/bin/Bash2Sh_dir=Sh_dir3  forRunshinch`ls$SH _dir |grep.SH`;4  Do5         Echo$runsh6result= './$SH _dir/$runsh '7         Echo$result8         Echo$result |grep '8'9 Ten         if[$?-ne0 ]; One          Then  A                 Echo "" -         Else -                 Echo "find it in $runsh" the         fi -  Done

The 5th and 7th lines can be commented out, and the display is clearer.

I think it might be a bit faster to implement Python. I think I've been learning python for a longer time.

Pseudo-code is similar to this, the for loop iterates through the executable file, then stores the result, using the if to make a comparison.

[Shell] Implements script execution results matching a string

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.