Linked Questions
14 questions linked to/from Reading lines from a file with bash: for vs. while
0
votes
0
answers
585
views
Whats causing my script is exiting while loop [duplicate]
What is causing this script to exit the loop at line "program is exiting loop here"? In the context it will loop twice but it won't if i have the CM_CHECK_STATUS where i have it.
RUNLOG=&...
0
votes
1
answer
54
views
What is wrong in this bash script? [duplicate]
For some reason, this script (run on RHEL v6.9) processes only the first line in the host_file
#!/bin/bash
process()
{
ssh $host ls
}
while IFS= read -r host
do
echo "Running $host"
process
...
240
votes
9
answers
328k
views
Looping through files with spaces in the names? [duplicate]
I wrote the following script to diff the outputs of two directores with all the same files in them as such:
#!/bin/bash
for file in `find . -name "*.csv"`
do
echo "file = $file";
diff $...
93
votes
7
answers
348k
views
How can I read line by line from a variable in bash?
I have a variable which contains multiline output of a command. What's the most effecient way to read the output line by line from the variable?
For example:
jobs="$(jobs)"
if [ "$jobs" ]; then
#...
106
votes
9
answers
72k
views
When would you use an additional file descriptor?
I know you can create a file descriptor and redirect output to it. e.g.
exec 3<> /tmp/foo # open fd 3.
echo a >&3 # write to it
exec 3>&- # close fd 3.
But you can do the same ...
107
votes
4
answers
151k
views
Why is `while IFS= read` used so often, instead of `IFS=; while read..`?
It seems that normal practice would put the setting of IFS outside the while loop in order to not repeat setting it for each iteration... Is this just a habitual "monkey see, monkey do" style, as it ...
43
votes
2
answers
62k
views
File descriptors & shell scripting
I am having a very hard time understanding how does one use file descriptors in shell scripts.
I know the basics such as
exec 5 > /tmp/foo
So fd 5 is attached to foo for writing.
exec 6 < /...
5
votes
2
answers
412
views
How to match name exactly with Bash's `help` builtin?
It seems the Bash built-in help command help does some really strange globbing:
help read shows the documentation for read, readarray and readonly.
help rea? shows only the documentation for read.
...
0
votes
2
answers
487
views
grep stringset as a single line
Let say in a text file if I do
grep FINAL *.msg
it returns
FINAL COMPUTATIONS: Elapsed Time: 000:30:55.65; CPU Time: 000:30:26.53
FINAL COMPUTATIONS: Elapsed Time: 000:28:11.77; CPU Time: ...
1
vote
1
answer
682
views
Making a bash script apply to only selected files (Nautilus)
I'm trying to learn (with no programming background) to create some custom bash scripts for converting selected files from Nautilus, but I hit an issue I can't understand.
For reference, this is a ...
2
votes
1
answer
223
views
How to get a list to be entered in quotes
I have a script that runs a python script (used to deduplicate emails via IMAP) after a user has entered a servername, username & password.
The first part of it gets a list of folders which the ...
0
votes
2
answers
296
views
how do I get my code to use the value of the $HOME variable?
I'm trying to put together a generic script that will check the existence of several key directories for various users on different servers. Additionally, I want to leverage each user's $HOME variable....
1
vote
1
answer
109
views
accessing substrings from lines in a text file and storing them
I have a text file like this
chr1:16840617-16840780 RNU1-1 (2 columns are tab separated)
chr3:142139047-142139211 RNU1-100P
............
............
I want to loop over the lines ...
1
vote
2
answers
69
views
Calling dir names from a paramater list file
Wondering if there is a best way to call directory names and iterate as parameter from a list.
Example
cat /dropbox/script/DirList.txt
DIR_A
DIR_B
DIR_C
DIR_D
/dropbox/dev/inbox/<DIR_A>/ *.*
/...