PLEASE NOTE: the upgrades to this server, secure.csse.uwa.edu.au, have not yet been completed.
Hopefully the changes will be completed on THURSDAY 8th December.
Web-based programs, such as csmarks, cssubmit, and the help fora, will be unavailable at some time on Thursday 8th.
  It's UWAweek 49

help2003/help4407

This forum is provided to promote discussion amongst students enrolled in Open Source Tools and Scripting.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying the 3 articles in this topic
Showing 3 of 564 articles.
Currently no other people reading this forum.


 UWA week 15 (1st semester, week 7) ↓
SVG not supported

Login to reply

👍?
helpful

I'm a bit lost as to when we can use ed-style pattern matching vs shell, and how the command interpreter would understand what "language" we used. For example, if I used ".*" in say, a case statement, when matching string patterns, how would the system know if I meant "search for a string pattern starting with "." and ending with anything or nothing" (shell), or "search for any string including an empty string" (ed)? Is it to do with certain commands which offer support for ed (like grep), while others don't? Is there a way to specify that you mean ed-style vs shell?


SVG not supported

Login to reply

👍x1
helpful

"Justin Hart" [email protected] wrote:

I'm a bit lost as to when we can use ed-style pattern matching vs shell, and how the command interpreter would understand what "language" we used.

For example, if I used ".*" in say, a case statement, when matching string patterns, how would the system know if I meant "search for a string pattern starting with "." and ending with anything or nothing" (shell), or "search for any string including an empty string" (ed)?

Is it to do with certain commands which offer support for ed (like grep), while others don't? Is there a way to specify that you mean ed-style vs shell?

Hi Justin,

Awesome question. To answer the first part of your question - yes, it is dependent on which commands that you are using; it is also dependent on what you are operating on too. (I would also add that these days we would call ed-style pattern matching 'regular expression/regex', as ed uses a subset of standard regular expressions given it is an older tool.)

For example, if you are using ls or other shell utilities on files (searching, checking, moving etc.) you would be expected to use file-based glob-style matching. If you are searching for the presence of a word inside a text file, this is not file-related and so you would expect to use a regex system of pattern matching instead.

To answer your question; if you are using shell-based constructs 'natively' (such as a wanted to use wildcards for file search) then you are implicitly using a globing approach. If you are searching for patterns inside text and you want to use regex pattern matching, you would either use a tool that uses these by default (a la. grep, sed etc.) OR the tool may provide an option to use regex (e.g. find will glob with wildcards by default (shell style), but you can use find -regex to instead match on regex style instead).

An additional explanation used to find some of these examples can be found on this forum post, too.

Hope this helps!

Ryan (lab guy).


SVG not supported

Login to reply

👍x1
helpful

"Ryan Bunney" [email protected] wrote:

"Justin Hart" [email protected] wrote:

I'm a bit lost as to when we can use ed-style pattern matching vs shell, and how the command interpreter would understand what "language" we used.

For example, if I used ".*" in say, a case statement, when matching string patterns, how would the system know if I meant "search for a string pattern starting with "." and ending with anything or nothing" (shell), or "search for any string including an empty string" (ed)?

Is it to do with certain commands which offer support for ed (like grep), while others don't? Is there a way to specify that you mean ed-style vs shell?

Hi Justin,

Awesome question. To answer the first part of your question - yes, it is dependent on which commands that you are using; it is also dependent on what you are operating on too. (I would also add that these days we would call ed-style pattern matching 'regular expression/regex', as ed uses a subset of standard regular expressions given it is an older tool.)

For example, if you are using ls or other shell utilities on files (searching, checking, moving etc.) you would be expected to use file-based glob-style matching. If you are searching for the presence of a word inside a text file, this is not file-related and so you would expect to use a regex system of pattern matching instead.

To answer your question; if you are using shell-based constructs 'natively' (such as a wanted to use wildcards for file search) then you are implicitly using a globing approach. If you are searching for patterns inside text and you want to use regex pattern matching, you would either use a tool that uses these by default (a la. grep, sed etc.) OR the tool may provide an option to use regex (e.g. find will glob with wildcards by default (shell style), but you can use find -regex to instead match on regex style instead). It is not the 'system' determining what style you are using - rather, the tool that you are passing the patterns/globing to that will interpret it accordingly.

An additional explanation used to find some of these examples can be found on this forum post, too.

Hope this helps!

Ryan (lab guy).

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  1:17AM Sep 14 2022
Privacy policy