Linked Questions
99 questions linked to/from Understanding "IFS= read -r line"
8
votes
5
answers
16k
views
Bash while loop read from colon-delimited list of paths using IFS
I am trying to write a bash function that behaves similarly to the where builtin in tcsh. In tcsh, where lists all the builtins, aliases, and the absolute paths to executables on the PATH with a given ...
7
votes
3
answers
4k
views
What does "${line#*'Caused By'}" != "$line" mean in a shell script?
Can someone explain what this means in a shell script?
while read -r line
do
if [ "${line#*'Caused By'}" != "$line" ]; then
echo "Yes"
fi
done
7
votes
5
answers
14k
views
Escape unusual characters on filenames with `find . -printf "%p \n"`
The file paths coming from this find command
find . -printf "%p \n"
do not escape unusual (whitespace, backslash, double quote...) characters.
The -ls option does print the escaped paths, but it ...
11
votes
2
answers
8k
views
A while loop and an here-document - what happens when?
I have this while loop and here-document combo which I run in Bash 4.3.48(1) and I don't understand its logic at all.
while read file; do source ~/unwe/"$file"
done <<-EOF
x.sh
y.sh
EOF
...
17
votes
1
answer
2k
views
What is the meaning of "<&3" and "done < file11 3< file22"
I have the following script:
while read lineA && read lineB <&3
do
echo "$lineA"
echo "$lineB"
echo
done < file11 3< file22
This code is working fine. But I don't ...
4
votes
6
answers
1k
views
Replace blank line with above line content
How do I replace the blank lines in tab delimited text file with the content of the row above on a Linux machine? For example:
101 abc group1
765 efg group2
345 hij group4
456 gfd group9
762 ert ...
2
votes
4
answers
3k
views
Unix bash/ksh : Selection of first non space character from file from specific line
I have file file1.txt whose contents are as follows:
Date List
-----------
Quarter Date
Year Date
Month Date
Now I want to read the non space elements from each row of file ...
5
votes
2
answers
20k
views
Bash Script Function Return True-False
I want to query the function by returning the value.
My codes are as follows;
check(){
file=/root/Turkiye.txt
local funkx=$1
while read line; do
if [ "$line" == "$funkx" ]
...
9
votes
3
answers
3k
views
"echo $IFS" does not return the value of IFS
I have set the IFS to x, i.e IFS=x. Now if I check the value of IFS, then it appears to be empty if I do not use double-quotes:
~ $ echo $IFS | cat -e
$
~ $ echo "$IFS" | cat -e
x$
~ $ echo $HOME
/...
2
votes
7
answers
2k
views
Shuffle words in a string
I have a text file with newline delimited strings. My problem is to process each line as follows: shuffle the order of tokens by using space as a delimiter.
For example:
Input:
A B C
Output:
C A B
...
2
votes
1
answer
4k
views
Compact way to get tab-separated fields into variables
In Bash, I'm reading out fields from a line into an array. Let me stress that performance is an issue, so I can't afford anything that spawns subprocesses.
To make the code more readable, I want the ...
1
vote
5
answers
9k
views
How to compare two files and if found equal ask the user to delete duplicate file by using shell script?
I am learning linux and was given this problem as my homework but i can't solve this that how we can compare two files content in shell mode.
(Here, we can assume that both files having text content ...
2
votes
2
answers
1k
views
How to split line in for loop and use as arguments to command line call
I have a seemingly very simple problem but I am unable to come up with a satisfying solution.
I have a simple input file containing IPs and ports, like
10.155.78.0 445
172.17.11.0 3389
Now I want to ...
6
votes
2
answers
1k
views
In bash, what is the difference between IFS= and IFS=$'\n'
Is there any difference between these three code blocks in bash?
Using IFS= :
#!/usr/bin/env bash
while IFS= read -r item; do
echo "[$item]"
done </dev/stdin
Using IFS=$'\n':
#!/usr/...
7
votes
1
answer
554
views
Why wait in this script is not executed after all subshells?
In this script, that pulls all git repositories:
#!/bin/bash
find / -type d -name .git 2>/dev/null |
while read gitFolder; do
if [[ $gitFolder == *"/Temp/"* ]]; then
...