Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Scripts dont give a consistent output.. Post 302981683 by Scrutinizer on Saturday 17th of September 2016 10:44:29 AM
Old 09-17-2016
Quote:
Originally Posted by bakunin
The "internal field separator" is a shell variable which tells the shell how separate "words" (=input fields) are separated from each other. Consider this command:

Code:
command arg1 arg2 arg3

Somehow the shell has to know why this is to parse as a call to "command" with three different arguments, "arg1", "arg2" and "arg3". The reason is that in fact the command looks (for the shells parser) like this:

Code:
<string1><IFS><string2><IFS><string3><IFS><string4>

and because the default value for IFS is a space the shell sees four strings, of which the first is a command and the others are arguments. This is why you have to quote "words" (commands, arguments) containing spaces: quotes turn off the mechanism inside them.
[..]
Not quite. In the example given, this is always a sequence of class [[:blank:]] characters, irrespective of the value of IFS :
Code:
<string1>[[:blank:]]+<string2>[[:blank:]]+<string3>[[:blank:]]+<string4>

Where [[:blank:]]+ means one or more characters from the [[:blank:]] character class (i.e. space or TAB).
When a line is read, this is determined during token recognition where it is determined that these are word tokens.

Then the shell grammar is used to determine that this is a simple command where the first field is the command name and remaining fields are the arguments for the command.

---
IFS is only used in the following cases:

To illustrate the difference:
Code:
$ bla=1,2,3
$ IFS=,
$ printf "%s\n" 1,2,3  4     # No field splitting, IFS is not used, besides %s\n there are 2 fields that were determined as words during token recognition: 
1,2,3
4
$ printf "%s\n" $bla  4      # Field splitting after variable expansion, IFS is used. Besides %s\n there are now 4 fields, one determined as word during token recognition, the other field is split into 3 further fields
1
2
3
4
$ printf "%s\n" "$bla"  4    # Variable expansion between double quotes, so no field splitting, IFS is not used, besides %s\n  there are 2 argument fields that were determined as words during token recognition: 
1,2,3
4
$ printf "%s\n" "$bla  4"    # Variable expansion between double quotes, so no field splitting, IFS is not used, besides %s\n there is one argument field after quote removal
1,2,3  4
$ IFS=$' \t\n'
$ printf "%s\n" $bla  4      # Field splitting after variable expansion, IFS is used, but the comma is not part of IFS, so no split is performed, besides %s\n there are 2 argument fields that were determined as words during token recognition: 
1,2,3
4


Last edited by Scrutinizer; 09-17-2016 at 12:33 PM..
These 3 Users Gave Thanks to Scrutinizer For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Routine doesn't give output when executed in crontab

I have a script running in the crontab that gets data from a database every hour. Now I would like to execute a fortran routine to process the data in some way, after getting it and saving it locally. I have added the following commands to my script: set convert =... (1 Reply)
Discussion started by: SharkM
1 Replies

2. Shell Programming and Scripting

Compare 2 files and give uniq output

Hi , Just to find out a way to compare these 2 files and give unique output. For eg: 1.txt contains 1 2 3 4 5 6 -------------------------------------- 2.txt contains 1 2 6 8 (1 Reply)
Discussion started by: rauphelhunter
1 Replies

3. Shell Programming and Scripting

check for the value of one particular field and give output in a different file

hi i need to check for the value of one particular field : in the output file. the file may contain many such records as below how to ???? *** Throttled with base name + key params! : : -518594328 : les.alarm.LBS12005 : les.alarm.LBS12005 : les : lessrv1 : les : 2328 : 0... (7 Replies)
Discussion started by: aemunathan
7 Replies

4. Solaris

metadevice submirrors 0 and 1 not consistent

At a new job, I've inherited a handful of Solaris 10 SunFire V240 servers. I noticed that the metadevices are not consistent, in a way that I've not seen before.... internal mirrored disks: metadevice d60 has c1t0d0s6 as submirror 0 (d61) and c1t1d0s6 as submirror 1 (d62) metadevice... (1 Reply)
Discussion started by: Max Power
1 Replies

5. Shell Programming and Scripting

give some color to a word on echo output

Hi Supposed this text output: How can I show $HOSTNAME in other color than blank? :-) KSH on AIX (4 Replies)
Discussion started by: iga3725
4 Replies

6. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

7. Shell Programming and Scripting

Script to give plsql procedure output

##Execute the EDW_MEM_KEY_UPDATE procedure ext_sta=`sqlplus -s ${Connstr} <<eof set heading off; set pagesize 0; set feedback off; set serveroutput on; execute EDW_MEM_KEY_UPDATE ; quit; here` vara="ORA-" var=`echo $ext_sta | grep -c $vara ` Hi All, above is a part of my unix... (7 Replies)
Discussion started by: iamnoone
7 Replies

8. Shell Programming and Scripting

How to give full access to output files created by .sh script run via crontab?

Hi Expert, I have a .sh script in my home/new_dir/script.sh This script creates number of output files at home/new_dir/email, home/new_dir/logs dir. I am running this script using crontab (owner root). Now this output files are getting created with rw-r----- 1 root root So if i... (2 Replies)
Discussion started by: Jeet1982
2 Replies

9. Shell Programming and Scripting

Nohup not give expected output. Non-stop running process

Hello, I am trying to make a bash script, I tested nohup but it did not help me. My code is: ffmpeg -i $input_url -c:v copy -c:a copy -listen 1 -f mpegts http://localhost:port/live/test When I open it in VLC, it starts feeding my screen and I see bitrate values. When I stop watching it,... (4 Replies)
Discussion started by: baris35
4 Replies
All times are GMT -4. The time now is 10:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy