ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Does AWK have the ability to assign fields? (The man page will tell you)
This:
Quote:
a=$1;b=$2;c=$3
--if it were to do anything, it would assign the 3 field values to the variables a,b,c
But--awk returns field values with--eg-- print $1, so I'm not sure what the quoted syntax does.
If shell variables are to be set and awk is preferred then awk can be used to write shell variable assignments for the shell to execute using eval
Code:
#!/bin/bash
value='18:46:52'
eval $( echo "$value" | /usr/bin/awk -F ':' '
{ print "a=" $1 " b=" $2 " c=" $3}
' )
echo "DEBUG: a is $a, b is $b and c is $c"
The technique of embedding awk in shell scripts can be very useful, for example when a lot of string data has to be handled (awk runs a lot faster than shell script). For debugging the first and last lines can be changed so the generated assignment statements can be viewed
Unsetting IFS is not exactly the same as setting it back to default. The differences are still a bit unclear to me, but it could lead to problems in specific circumstances. I think it mostly affects how the shell treats null separators.
Better to store the original IFS away, then restore it when you're finished.
Unsetting IFS is not exactly the same as setting it back to default. The differences are still a bit unclear to me, but it could lead to problems in specific circumstances.
It is not exactly the same because IFS does not exist any more but it is functionally (effectively) the same as documented in the links in this LQ post.
Hmm. I must've missed your last response on that thread somehow. I know it was that thread I was thinking about that prompted me to post here. So I guess it's safe. But it would still be nice to confirm it 100%.
Truly. It is unfortunate that the documentation is not conclusive and only implies it. We are left having to confirm it by usage -- until anyone reports an exception -- unless someone analyses the source code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.