Hi there,
I'm using two commands that need different IFS.
The mysql command need IFS to include space because I'm given the mysql command as a variable:
If IFS doesn't include space, then $MYSQL is considered as one word and not command + switch:
The read command needs IFS to include tab and exclude space:
If IFS include space, then mysql output is not correctly interpreted:
I have to run this kind of queries many time in the script and thought it's a pain in the ass to set IFS two times every time I run a query.
Is there any way I can write something like:
Instead of:
I got lost in your post, but in general I leave IFS alone so it has its default global value. Then if I need a special setting, I set it for that one command:
while IFS="" read line ; do
as one example. There the read statement gets its own IFS setting, but everything else gets the default. You just put the IFS value in front on the command.
Thanks Perderabo for your help.
I knew this trick for while read and that was the bases of my attempts.
Could you then explain me why I have to put the statement between braces?
Update: If I don't put the braces, IFS is modified for the entire script.
Last edited by chebarbudo; 03-11-2009 at 09:57 PM..
Reason: update
You should not need the braces and I cannot explain why you do. I'll try it tomorrow. The bash man page states:
The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described above in PARAMETERS. These assignment statements affect only the environment seen by that command.
The behavior you report violates that last sentence.
I got lost in your post, but in general I leave IFS alone so it has its default global value. Then if I need a special setting, I set it for that one command:
while IFS="" read line ; do
as one example. There the read statement gets its own IFS setting, but everything else gets the default. You just put the IFS value in front on the command.
I find that some shells(bash) treat IFS specially, overwriting it when you wouldn't expect it to.
I find that some shells(bash) treat IFS specially, overwriting it when you wouldn't expect it to.
One more reason for me to stay with ksh. I do that all the time with ksh and I never observe unexpected behavior involving IFS. I'll try it with bash tomorrow and see what happens.
In the perl below, which does execute, I am having trouble with the else in Rule 3. The digit in f{8} is extracted and used to update f accordinly along with the value in f.
There can be either - * or + before the number that is extracted but the same logic applies, that is if the value is greater... (5 Replies)
Ok, so I'm playing around with delimters and reading files. and I came across this behaviour that I thought was a bit odd, regarding how the set command takes values... If I run this: IFS=$'-' #Assigns the - as the default delimiter for bash set I-love-my-gf-a-lot #uses set to put a bunch of... (1 Reply)
Hi all,
I have this script which sends mail whenever the system is down. It works fine. Normally the system is down from 21 00 to 21 30 from Monday to Saturday and from 21 00 on Sunday to Monday 06 00 for maintenance. So I want the below script to run only when the system is up, i.e outside the... (2 Replies)
This could be a really dummy question.
I have a log text file.
What unix command to extract line from specific string to another specific string.
Is it something similar to?:
more +/"string" file_name
Thanks (4 Replies)
I have a file that needs 1st line, 2nd line, and 26th line printed from every chunk of data. Each chunk of data contains 26 lines (#line+%line+24 data lines = 26 lines of data repeated).
Input file:
# This is a data file used for blockA (chunk 1).
% 10576 A 10 0 1
04 (data1)
03 (data2)... (2 Replies)
Apologies for the utter triviality of this question, but we all have to start somewhere! I've also tried searching but this question is pretty vague so I didn't (a) really know what to search for or (b) get many relevant hits to what I did search for.
Anyway, I'm in the process of self-teaching... (1 Reply)
Hello, I have a problem that I'm having quite a bit of trouble with.
I am trying to create a script that performs a specific sequence of actions for a file of a specific type.
This is an abbreviated version of my basic script:
#!/bin/sh
#coulombic calculations... (2 Replies)
I am trying unsuccessfully to set into a variable a specific part of command output:
The command output will be as:
line 1: <varied>
line 2: 2 options:
option 1:
Set view: ** NONE **
or
option 2:
Set view: <different_name_of_views_always_without_spaces>
and I would like to get into... (7 Replies)
Hi!
I am working in korn shell. I want to reset the dimiliter for the set command to "|" but instead of a command prompt return I am getting something as below
After issuing the command I am getting this....as if the shell is expecting something else. Can anybody suggest what's the problem.
... (2 Replies)