Linked Questions

0
votes
1answer
27 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 ...
135
votes
10answers
171k 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 $...
78
votes
4answers
83k 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 ...
70
votes
7answers
37k 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 ...
42
votes
6answers
183k 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 #...
32
votes
1answer
40k 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 < /...
4
votes
2answers
221 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. ...
2
votes
1answer
79 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
2answers
65 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
1answer
62 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
2answers
36 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>/ *.*...