Questions tagged [ifs]

IFS is a variable in Unix shells (Bourne, POSIX sh, bash, ksh, …) that controls how unescaped substitutions are split into words.

IFS (short for "input field separator" and often referred to as "internal field separator") is a variable in Unix shells (, , , , , , , , …) that controls how strings are split into multiple fields. Most notably, variable substitutions (e.g. $foo) which are not inside double quotes or in a few other protected locations are split into multiple fields based on the value of IFS; the same goes for command substitutions (e.g. $(foo)). Each character that is present in IFS is a field separator. The default value contains a space, a tab and a newline.

For other meanings of the acronym IFS, use the appropriate tag:

  • IBM Integrated file system
  • QNX Image Filesystem
  • ERP by Industrial and Financial Systems AB
293 questions
1
vote
1 answer

Complex nested IFS in excel

So I have this output to track my tickets system that has the following columns: 1. create date 2. resolved date 3. location (A,B,C,D) 4. item (1,2,3,4) How do I create a formula that could give me an output of average days open of an item in a…
trouble
  • 11
  • 1
  • 4
1
vote
2 answers

Word splitting using multiple IFS

Being new to shell scripting, I am not clear about the Quoting and splitting concepts in bash. In the below snippet: array1=("france-country":"Italy-country":"singapore-country") echo ${#array1[@]} IFS=":-" for i in ${array1[@]} do echo…
user13252
  • 75
  • 1
  • 7
1
vote
2 answers

Prevent IFS to stop on new lines

I have a multiline string which I want to transform into an array by using a single delimiter |. However, when setting IFS=| it will stop right before a new line appears: IFS='|' read -a VARS <<< "var1|var2|var3 …
zanona
  • 12,345
  • 25
  • 86
  • 141
1
vote
2 answers

Unset IFS value for shell script

In my use case I would like to change the value of IFS to a known separator (-). I tried the following: OLDIFS=$IFS IFS='-' for x in $* do echo $x done IFS=$OLDIFS When using e.g. -a b -c d as input string I expect the output to be a b c…
Aymanadou
  • 1,200
  • 1
  • 14
  • 36
1
vote
1 answer

Strangeness in bash: different behaviour inside heredoc

I'm having a strange problem with a bash-script. The minimal code to reproduce it is here: #!/bin/bash function f() { IFS=. read a b <<<"$1" echo "a=$a b=$b" } f a.b echo "inside echo: `f a.b`" cat <
Niobos
  • 880
  • 4
  • 15
1
vote
2 answers

Preventing leading spaces from getting ignored using IFS=

I am trying to insert few lines before a specific line in an xml file. Though it's working but the formatting is not retained. Leading whitespaces are getting ignored. I know that we have to use IFS= and i also cross-checked it in the following link…
Technext
  • 7,887
  • 9
  • 48
  • 76
1
vote
3 answers

Split a namefile in shell

I'm here to know how to split a file name that was found by a ls comand :D. Let me explain better... I have a variable images=$( ls | grep .img ) And then i want to split the result of the search, because i just want the name before the .img, so a…
ranu
  • 622
  • 15
  • 25
1
vote
4 answers

Splitting line of text into array at bash

I have a bunch of files named jtn216_.o where n and m are integer. The first one is assigned by me and the second one by the system. I need to check the last line at each file. I ran this to split that line into array for i in {361..380}; do…
Yotam
  • 10,295
  • 30
  • 88
  • 128
1
vote
2 answers

How is this bash script resulting in an infinite loop?

From some Googling (I'm no bash expert by any means) I was able to put together a bash script that allows me to run a test suite and output a status bar at the bottom while it runs. It typically takes about 10 hours, and the status bar tells me how…
redbmk
  • 4,687
  • 3
  • 25
  • 49
1
vote
1 answer

Use of the Internal Field Separator when capturing array data from a command in a bash script

When I run the command git cherry origin/Server_Dev in my git repository, I get a list of commits of the form + 95b117c39869a810595f1e169c64e728d2d7443d + e126f1b996ecf1d2a8cf744c74daa92cce338123 + 869169a6cb0bbe8f1922838798580a1e74ec3884 +…
user360907
0
votes
0 answers

Excel bugs in formula

I can't use the IFS formula in EXCEL. The formula is? =SES(X2>=Concluído;Concluído;X2>=Concluído/Em Validação Controles;Concluído/Em Validação Controles;X2>=Concluído/Em Validação Rev. Independente;Concluído/Em Validação Rev. Independente;X2>=Em…
Marcel
  • 1
0
votes
1 answer

If function that searches a column for ''text''

I am building a google sheet to autogenerate a report. I have a table that populates itself but I want an image to appear at the top of the page if "IN-36" Appears in column C of "Equipment" tab. I currently have…
0
votes
3 answers

Delimiter to split Bash function arguments as an array of strings

For a Bash function my_fun, how can I use a delimiter (e.g. ";") to split input into an array of strings? Example input: $ my_fun This is ; an example Example output: string1: This is string2: an example Perhaps using $IFS=';' or the read command?
0
votes
2 answers

IFS formula not returning correct values

=IFS(F38=1,"Not Satisfactory",F38>=1.5,"In Progress",F38>=2.5,"Good",F38>=3.5,"Very Good",F38>=4.5,"Excellent") The formula returns correct values for "Not Satisfactory" and for "In Progress"; I can´t understand why for the remaining 3 (Good, Very…
Avallon
  • 3
  • 1
0
votes
2 answers

While, do, done flow control in bash

Can anyone explain the control flow of the following bash script? while IFS= read -r file do rm -rf "$file" done < todelete.txt From what I understand, this would happen: IFS would be assigned nothing. The rm -rf command would do nothing because…