Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
2. How awk can actually use the correct value for $i in the first script when it is enclosed in single quotes? I previously thought that single quotes kill any and all special meaning. This is as literal as you can get? How is the expansion working correctly in this case? Is there something special about using the / /, which is specific to regex?
First off ` /= '. A back tick (`) which is part of the tilde (~) key above the tab key is not a single quote ('). You are right in saying that single quotes change the meaning of a command where echo "$PATH" and echo '$PATH' give two different outputs.
I'm no awk expert but I don't believe you can simply pipe the output of a command like that from within awk. To execute commands you have to use the system function for example system("date"). As for the rest I'll defer someone else who would know better.
By the way in your awk command the $i is not enclosed by single quotes. It is outside of them. Below I have highlighted the quoted text.
I'm no awk expert but I don't believe you can simply pipe the output of a command like that from within awk. To execute commands you have to use the system function for example system("date").
It might depend on the version of awk. It is part of at least the current GNU awk as described here.
/dateVal/ looks for exactly that, without substituting the value of dateVal. If you want to use a variable value as a regular expression then awk's dynamic regexp provisions apply. The code would be something like (not tested, spread over several lines and indented for legibility)
First off ` /= '. A back tick (`) which is part of the tilde (~) key above the tab key is not a single quote ('). You are right in saying that single quotes change the meaning of a command where echo "$PATH" and echo '$PATH' give two different outputs.
I'm no awk expert but I don't believe you can simply pipe the output of a command like that from within awk. To execute commands you have to use the system function for example system("date"). As for the rest I'll defer someone else who would know better.
By the way in your awk command the $i is not enclosed by single quotes. It is outside of them. Below I have highlighted the quoted text.
cool. this works. so, looking at the color coding above `date +%F` is outside the quotes as well. if this is the case, how do we get away with the syntax? shouldn't awk just choke?
/dateVal/ looks for exactly that, without substituting the value of dateVal. If you want to use a variable value as a regular expression then awk's dynamic regexp provisions apply. The code would be something like (not tested, spread over several lines and indented for legibility)
cool. this works. so, looking at the color coding above `date +%F` is outside the quotes as well. if this is the case, how do we get away with the syntax? shouldn't awk just choke?
bash substitutes the output of date +%F for `date +%F` before awk sees it. So, for example, awk sees (using colour to identify individual "words" as given to awk)
EDIT: BTW, you may prefer to use $( ... ) instead of ` ... `. It is functionally superior in complex cases but more importantly it is obviously not a single quoted string which the ` .. ` form can be mistaken for.
bash substitutes the output of date +%F for `date +%F` before awk sees it. So, for example, awk sees (using colour to identify individual "words" as given to awk)
EDIT: BTW, you may prefer to use $( ... ) instead of ` ... `. It is functionally superior in complex cases but more importantly it is obviously not a single quoted string which the ` .. ` form can be mistaken for.
excellent....I'm one step closer to understanding the order of operations for shell expansion ...thx
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.