Questions tagged [read]

`read` is a shell utility used for reading strings from the standard input stream, or from a file descriptor.

Filter by
Sorted by
Tagged with
1 vote
0 answers
39 views

How to run input (x|grep y) in command

lets say when I execute command and then grep it for a specific output. for example: man cat|grep "Written" This gives the name of the authors. My problem is I want to do this via read. here ...
user avatar
0 votes
2 answers
38 views

Trying to create a while loop to output content of one file to another

I am trying to create a while loop so that it takes content from one file and creates some content on another file. But what i noticed is that it is only creating the last line of the file instead of ...
user avatar
4 votes
1 answer
254 views

What does the "-d" option of the "read" shell command do when I use it with an empty string as argument?

While I was reading this answer, the author used this command to put the result of a heredoc to a variable: read -r -d '' VAR <<'EOF' abc'asdf" $(dont-execute-this) foo"bar"'' EOF ...
user avatar
0 votes
0 answers
55 views

redirected stdin : how to get ALL lines of the incoming request instead of doing multiple "read"

THIS QUESTION IS BASH SCRIPT RELATED... the rest is to explain the context. context : experimentation : create a simple mini webserver with socat instead of apache. ** the test I'm doing is able to ...
user avatar
  • 115
3 votes
1 answer
63 views

How to sort out the wrong entries in the most simple way depending on the corresponding line in the other file?

I have two files: In one I have a list of strings, which need to removed if the corresponding line in the other file contains a string "NOPE". If it contains "YES" it stays there. ...
user avatar
-1 votes
1 answer
40 views

write bash code loop a file line by line that have values, first word as a row and create csv [closed]

i have this sample data dn; uid=456456456,cn=users,dc=efsfb,dc=org,dc=co; objectclass; top; objectclass; person; objectclass; organizationalPerson; objectclass; inetOrgPerson; uid; 456456456; ...
user avatar
  • 101
0 votes
1 answer
95 views

How to read numbers of rows and columns and print in a specific way

I need to make a shell script that will receive a number of rows and a number of columns and then print a word as the number of rows and columns. For example: 2 rows, 3 columns expected output: word ...
user avatar
  • 3
0 votes
0 answers
12 views

How to expand regex from lines in a file similar to echo on command line? [duplicate]

I have a list of strings in a text file. The strings have regular expression ranges/lists in them. I want to be able to expand all the possibilities. It works if I select a string and paste it after ...
user avatar
  • 1
0 votes
1 answer
49 views

Splitting a null separated string

Hereafter are two read statements, one that uses a space as a delimiter, and the other \0. Only the first works. What am I doing wrong with the second? $ IFS=' '; read first second < <(printf &...
user avatar
  • 481
0 votes
2 answers
58 views

Unable to match a specific regex with bash

I have a txt file with content as such: Adedunmola Okikiola Adewole 512.035 215−39 ^M Ademir Cleto de Oliveira 055.735 445−13 ^M Adilson ...
user avatar
  • 143
2 votes
1 answer
132 views

posix bash, how to read a csv file and ignore some columns?

on a POSIX shell, no Python and no awk available (so don't bother telling me I should use a "real" programming language) I have to loop through a csv file. https://datacadamia.com/lang/bash/...
user avatar
  • 123
0 votes
0 answers
26 views

Read-while loop with 2-field tabulated data: cannot print second variable before first [duplicate]

I have a 2-field csv file with the following values: subID,Task A,BLOCK B,BLOCK C,Finger Reading via a read-while loop, if I print the two fields in order... while IFS=',' read -r -a vars ; do ...
user avatar
  • 13
0 votes
1 answer
31 views

Filter changing file periodically and redirect filtered output to new file

Suppose I have log.txt The sample of log.txt are like these format: Code Data Timestamp ... C:57 hello 1644498429 C:56 world 1644498430 C:57 water 1644498433 ... If I want filter string line that ...
user avatar
1 vote
0 answers
35 views

How to resolve environmental variables in read command like they are resolved when being passed as parameters to a script

I have a script that can either be passed arguments at invocation, or display a prompt with instructions if none are passed. I can pass $FILE_LOC as an parameter and that gets expanded before being ...
user avatar
  • 25
0 votes
1 answer
129 views

Invalid arithmetic operator (error token is " 7.16.3 when passing float from read command

I am trying to automate software update with bash script. When I am passing version number e.g 7.16.3 I get following error: ") Syntax error Invalid arithmetic operator (error token is " I ...
user avatar
1 vote
1 answer
61 views

Read file from user input with a list of prefixes, then call file with prefixes in while loops

I am trying to direct user input file into while loop, but kept on failing when ran the script. The user input file genelist contained a list of numbers where I have been using as prefixes of my other ...
user avatar
  • 165
1 vote
1 answer
81 views

reading filenames with newlines

Now we're all familiar with not using: find . -print | xargs cmd but using find . -print0 | xargs -0 cmd To cope with filenames containing e.g. newline, but what about a line I have in a script: ...
user avatar
  • 53
6 votes
2 answers
579 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/...
user avatar
  • 403
2 votes
2 answers
92 views

No keyboard output on terminal after running a script using read and whiptail

I've written a bash function that accepts a command as an argument, runs it in the background, and allows the user to kill the command by pressing any key. This part works fine. However, when I pipe ...
user avatar
  • 35
0 votes
2 answers
63 views

Since read has a built in variable $REPLY, why do we need to explicitly state $line or other variable

While reading line by line, and IFS set to null, we can write: while IFS= read -r line do echo "$line" done < <(find . -name "*.txt") Is this not the same as: while read ...
user avatar
  • 111
0 votes
1 answer
89 views

Password protection for a file for 'write'

My requirement is to to protect a file with password. The user should be able to write/edit the file only after password authentication. But the user should be able to read the file without password ...
user avatar
  • 1
0 votes
1 answer
180 views

Why does "grep foo bar" print "grep: bar: Is a directory" instead of printing any filenames in bar/ that match the pattern "foo"?

The man page for grep describes the -d ACTION option as follows: If an input file is a directory, use ACTION to process it. By default, ACTION is read, i.e., read directories just as if they were ...
user avatar
0 votes
1 answer
253 views

Using a BASH script to read the output displayed in console from a third source?

I am having issues understanding how to get read to "read" information from the console instead of user input. Effectively "getline"? from console. Here is my scenario. I will be ...
user avatar
  • 25
2 votes
1 answer
416 views

script with `read` in bash while loop causing high CPU usage when run as a systemd service

I wrote a script to run specific actions conditional on input events informed by an event monitor, which looks something like $ cat script.sh -----------------------------------------------------------...
user avatar
  • 98
4 votes
4 answers
566 views

Read file and store as array without skipping empty strings

File.tsv is a tab delimited file with 7 columns: cat File.tsv 1 A J 1 2 B K N 1 3 C L O P Q 1 The following reads File.tsv which is tab delimited file ...
user avatar
  • 1,362
1 vote
1 answer
87 views

How to avoid losing my escape characters when reading in variables from a file with bash

I have a lab ntlm-extract.ntds file which has usernames and hashes in the format: domain\username:integer:hash:hash2 For example: somedomain.local\jcricket:5201:0020cfaecd41954fb9c9da8c61ccacd7:...
user avatar
  • 853
0 votes
3 answers
599 views

Providing input for multiple read(stdin) calls via bash input redirection

Suppose we have the following program, which calls read() twice: #include <stdio.h> #include <unistd.h> #define SIZE 0x100 int main(void) { char buffer1[SIZE]; char buffer2[SIZE];...
user avatar
  • 111
1 vote
1 answer
720 views

how to get user input with a prompt into a variable in a posix compliant way

read -r -p "put an option: " option echo $option this works but shellcheck gives me: In POSIX sh, read -p is undefined. How to get user input with a prompt into a variable in a posix ...
user avatar
0 votes
0 answers
90 views

How to configure samba for a shared folder for 2 groups, each with write and read access on all files [closed]

I need to create a samba shared folder, 2 users must have access this folder with write and read capabilities on all files, they should be able to modify and read each others files on the full ...
user avatar
0 votes
2 answers
224 views

Listing PCI Devices By Reading From File (Instead of lspci Command)

I need to read PCI device information from files. But it gives unusable output when I use command like that: cat /proc/bus/pci/05/00.0 Output: �h�� How could I fix this? OS: Debian-like Linux x64, ...
user avatar
  • 15
0 votes
2 answers
109 views

Read command removes double space and keeps only one

I wrote a script that collects application logs on local machine and then from remote machine. It has variable oldlogsdate which reads the date of logs I want to collect. For example, if I enter Apr ...
user avatar
  • 3,834
3 votes
1 answer
256 views

backtick or Here string or read is not working as expected in RHEL 8

I am trying to redirect the output of a python script as an input into an interactive shell script. test.py print('Hello') print('world') Say test.py is as above prints "Hello world" which ...
user avatar
0 votes
2 answers
567 views

How can I read from named pipe line by line and exit?

I have the following bash script that I'd like to use as a fuzzy file opener. I create a fifo, spawn a new terminal with fzf running and redirect fzf's output to the fifo. I then call a function that ...
user avatar
  • 347
6 votes
2 answers
1k views

Can read() return value exceed the count value?

With the below function signature ssize_t read(int fd, void *buf, size_t count); While I do understand based off the man page that on a success case, return value can be lesser than count, but can the ...
user avatar
  • 71
0 votes
1 answer
66 views

How to read my file correctly?

I have a question about how to read my file correctly in UNIX, I have the file given (attached as image) and this file has tabs between the variables, as you can see Blood is a variable and Whole ...
user avatar
2 votes
1 answer
82 views

Initialize several bash variables with the output of a single command

My goal is to initialize multiple bash variables from the output of one single command. Specifically, line i should be the value of variable i. Example: My command is a Python program with the name ...
user avatar
0 votes
0 answers
21 views

How to expand variables inside read without envsubst, arguments or heredocuments (and without any non shell-builtins)? [duplicate]

Perhaps I have misunderstood Stéphane Chazelas's answer here so I ask another question. In Bash desire to expand variables inside read without envsubst, arguments or heredocuments (and without any ...
user avatar
-1 votes
1 answer
45 views

read with an hyphen fails while read with an underscore succeeds

On a CentOS with Bash 5.0.17 I try to execute: read x-y -bash: read: `x-y': not a valid identifier read x_y Success: No error and the variable is saved. What might cause that problem and how would ...
user avatar
0 votes
1 answer
22 views

How to verify if current command prompt contains already-typed characters

I'm binding a function of mine to hotkey: bind -x '"\em": __my_function' I would like the function to behave differently depending on if the command line prompt already contains characters ...
user avatar
  • 274
0 votes
0 answers
58 views

Setting IFS with read not behaving as expected

Wondering if any of the good folks here can explain what is happening. The values seem to be being parsed out of the input string, but all stored in the first variable. bash-4.2# SYNC_REPO='vendor:...
user avatar
  • 1
2 votes
1 answer
72 views

Is read -r only used in rare exceptional usecases of read?

According to this manual -r for read: Do not allow backslashes to escape any characters I understand that generally, the read shell builtin gets input and creates a variable which holds that input ...
user avatar
0 votes
0 answers
58 views

How to prompt a user for variables without read? [duplicate]

I work with CentOS and the only shell I work with is Bash. I am trying to develop a Bash script which configures a content management system and I seek a way to make this script web application ...
user avatar
4 votes
1 answer
681 views

How to expand variables inside read?

In a remote CentOS with Bash 5.0.17(1) where I am the only user via SSH I have executed read web_application_root with: $HOME/www or with: ${HOME}/www or with: "${HOME}"/www or with: &...
user avatar
2 votes
0 answers
129 views

Strange Cygwin terminal behaviour with trap and stty -echo

If I exit the script with Ctrl+C during the read ... command, the stty -echo mode is stuck! (I'm using the Cygwin terminal on Windows 10.) Unfortunately read -s won't solve my problem as it is "...
user avatar
  • 309
6 votes
5 answers
1k views

IFS=',' /usr/bin/read vs IFS=',' read

Context $ bash --version GNU bash, version 4.4.19(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/...
user avatar
  • 61
0 votes
1 answer
54 views

while read loop not working inside alias [duplicate]

In Bash, the following command echo foo | while read line; do echo $line; done outputs foo; however, the following alias bar="echo foo | while read line; do echo $line; done" bar outputs a ...
user avatar
  • 115
3 votes
1 answer
185 views

How to read binary data including zero bytes using BASH builtin read?

I found bash ignores binary zero on input when reading using the read buildin command. Is there a way around that? The task is reading from a pipe that delivers binary data chunks of 12 bytes at a ...
user avatar
0 votes
0 answers
54 views

How to get read working again after while loop in bash

#!/bin/bash echo "Export Tape(s):" echo "---------------" stdbuf -oL echo "list media" | bconsole | { while IFS= read -r line do line=$(echo ${line^^}) ...
user avatar
  • 585
10 votes
3 answers
1k 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 ...
user avatar
  • 32.6k
4 votes
3 answers
640 views

Why must I put the command read into a subshell while using pipeline [duplicate]

The command df . can show us which device we are on. For example, me@ubuntu1804:~$ df . Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdb1 61664044 8510340 49991644 15% /home ...
user avatar
  • 2,809

1
2 3 4 5
7