Linked Questions

0 votes
0 answers
200 views

how to expand a variable with backslash in bash script [duplicate]

i read a line from another file that contains a backslash, and i want to echo this line without expanding the backslash : script.sh : #!/bin/bash while read line do echo "$line" done &...
  • 111
262 votes
5 answers
64k views

Why is using a shell loop to process text considered bad practice?

Is using a while loop to process text generally considered bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
  • 148k
119 votes
6 answers
50k views

Why is setting a variable before a command legal in bash?

I've just encountered several answers such as to parsing a delimited text file... that use the construct: while IFS=, read xx yy zz;do echo $xx $yy $zz done < input_file where the IFS ...
  • 1,295
25 votes
7 answers
33k views

`tail -f` until text is seen

I've got a CI server with a command-line interface that allows me to remotely kick-off a job (jenkins CI server and the jenkins-cli.jar tool). After I kick the job off I tail -f the log (sorry for ...
30 votes
7 answers
26k views

Read a line-oriented file which may not end with a newline

I have a file named /tmp/urlFile where each line represents a url. I am trying to read from the file as follows: cat "/tmp/urlFile" | while read url do echo $url done If the last line doesn't ...
  • 94.7k
24 votes
3 answers
15k views

Are files opened by processes loaded into RAM?

Commands, for instance sed, are programs and programs are codified logic inside a file and these files are somewhere on the hard disk. However when commands are being run, a copy of their files from ...
  • 3,500
14 votes
6 answers
7k views

If using while read loops for text processing in bash is bad...what should I do, then?

I guess this may be a naive question but I can't get my head around so I felt like asking... I was searching for some solution to a problem, when I found this very interesting post about why is using [...
  • 371
21 votes
2 answers
4k views

Ask for a password in POSIX-compliant shell?

When I want to ask for a password in a bash script, I do that : read -s ...but when I run bash in POSIX mode, with sh, the -s option is rejected: $ read -s sh: 1: read: Illegal option -s How do I ...
  • 621
13 votes
6 answers
7k views

How can I add random string for each line?

I'm trying to add random string for each line while running: awk '{print "name" "'$ran'" "-"$0}' 'myfile' Before that, the random string is generated: ran="$(tr -dc '[:alnum:]' </dev/urandom | ...
6 votes
7 answers
22k views

How to compare 2 strings in UNIX shell script? [duplicate]

I have a variable which stores a string, the output of a sed command. I want to execute a set of commands only if this string value matches either of the 2 other strings. I used the below code. #! /...
  • 125
16 votes
3 answers
9k views

How to read different lines of a file to different variables?

I would like to read different lines of a text file to different variables. For example input.txt: line1 foo foobar bar line2 bar line3 foo line4 foobar bar I want this result to be stored in ...
  • 169
14 votes
4 answers
3k views

How to add new line between `ls -l` output

This is standard ls -l output. user@linux:~$ ls -l total 0 -rw-rw-r-- 1 user user 0 Nov 1 00:00 file01 -rw-rw-r-- 1 user user 0 Nov 1 00:00 file02 -rw-rw-r-- 1 user user 0 Nov 1 00:00 file03 ...
user avatar
9 votes
4 answers
2k views

Performance of loop vs expansion

Need expert suggestions on below comparison: Code Segment using loop: for file in `cat large_file_list` do gzip -d $file done Code segment using simple expansion: gzip -d `cat ...
10 votes
3 answers
2k views

For what purpose does "read" exit 1 when EOF is encountered?

The bash man page says the following about the read builtin: The exit status is zero, unless end-of-file is encountered This recently bit me because I had the -e option set and was using the ...
  • 34.5k
6 votes
3 answers
35k views

Find command - argument list too long

Oracle Linux 5.10 BASH shell [oracle@src01]$ getconf ARG_MAX 131072 [oracle@srv01]$ ls -1 | wc -l 40496 #!/bin/bash # # delete files in /imr_report_repo that are older than 15-days find /...
  • 329

15 30 50 per page
1
2 3 4 5
7