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
0
votes
1answer
36 views

Filter script output during runtime

I have a script that runs about 10 other scripts in the background that constantly generate new output. I would like to keep that initial script running and be able to simply type in it to filter all ...
1
vote
2answers
580 views

What does these commands do?

I am using these commands in Linux Kali but I keep getting an error when I run the second command: "No such file or directory found." end=7gb read start _ < <(du -bcm kali-linux-1.0.8.amd64.iso ...
0
votes
2answers
24 views

How to read two variables under one read command and echo them separately?

For example: I want user to input A=a and I have the command which I guess is totally wrong. read -p "Enter something:" frsstring=secstring echo $frsstring echo $secstring ``````````````````````````...
1
vote
1answer
244 views

read(2) blocking behaviour changes when pts is closed resulting in read() returning error: -1 (EIO)

I'm trying to figure out how I can reliably loop a read on a pt master I have. I open the ptmx, grant and unlock it as per usual: * ptmx stuff */ /* get the master (ptmx) */ int32_t masterfd = open("/...
-9
votes
1answer
109 views

Using bash, how to read specific lines of a file? [duplicate]

I am looking to read portions of a file, for example lines 30-80, then later lines 81-130, then later lines 131-161, etc. Is there a way to read specific sections of lines or bytes of a file using ...
5
votes
2answers
997 views

What's the zsh way to read n characters from stdin?

In bash, if I wanted to read, say 3, characters from a pipe, I could do: ... | read -n3 In zsh's read, the closest option seems to be -k: -k [ num ] Read only one (or num) characters. All are ...
2
votes
1answer
72 views

How to determine if result of process substitution is a file path

If I do this: echo <(cat) I get: /dev/fd/63 so say at the command line I have: myapp -f <(cat) when I run it I get this error: You need to pass a file after the -f flag. The resolved ...
2
votes
2answers
123 views

Read command in shell script - variable input substitution

I am new to Linux, pardon any wrong terminology used here. I am using Ubuntu 18.04. I am reading text in a shell script using read command. I have a variable in bash window that I want to substitute ...
4
votes
1answer
947 views

Custom tab-completion in bash's `read`

Is there a way to "import" a list of words into bash's read builtin to have custom tab-completion? I've been writing a wrapper script for suckless' minimalist irc client "ii", and I don't have a way ...
1
vote
1answer
71 views

Copy a row in a CSV file based on a value in another column

I have a file of 800+ rows. Each row has a certain number of individuals we have to measure a trait on (n = 3, 5 or 10). I would like to expand the file so each individual has their own row based on ...
1
vote
2answers
74 views

Shell script on “read” accept via both enter key and tab key

in shell script when you have the following : read my_variable Enter is the key that saves your input. is there a way to make Tab accomplish the same as Enter without removing Enter's functionality?...
6
votes
2answers
9k views

bash: non blocking read inside a loop

I have a following small bash script var=a while true : do echo $var sleep 0.5 read -n 1 -s var done It just prints the character entered by the user and waits for the next input. What ...
21
votes
2answers
29k views

What is the meaning of read -r ?

in order to understand another answer: find / -type d -print0 | while read -r -d ''; do ls -ltr "$dir" | sed '$!d' the first step is to understand the usage of the option -r of the read command. ...
1
vote
1answer
37 views

Reading data from serial port

FYI I am running busybox. I am able to send data to my ttyS1 using the following command: stty -F /dev/ttyS1 speed 115200 cs8 -cstopb -parenb -echo echo -en 'data here' > /dev/ttyS1 But when I ...
0
votes
0answers
39 views

How to create program that automatically removes old lines

Say I have a simple pipeline: receive-data | write-to-file --max-lines 500 -f <file> how can I implement a program write-to-file where the max number of lines is 500 or some number? (It can ...
1
vote
2answers
39 views

If I know how many lines to go down, how do I know where to start in the file in terms of bytes

I want start read()'ing a file at a certain position. I know how many lines to start reading at - but read() doesn't take lines as an argument, it takes bytes for position. Is there some trick I can ...
0
votes
3answers
198 views

How to read input lines with newline characters from command line?

I found this to get user input from the command line. But it is failing into recognizing the new line characters I put into the input. Doing: #!/bin/bash read -e -p "Multiline input=" variable; ...
0
votes
1answer
134 views

read user input into array until user enter specific entry

i need to create a bash that get input from user and insert them into an array until user enter an specific thing. for example, if i run script: enter variables: 3 4 7 8 ok i get this array: ...
0
votes
2answers
46 views

Bash - here doc read input value from another user

I have a here document inside a bash script. I want to read a value from it like that : su myUser<<SESSION set -x echo -n "Enter your name and press [ENTER]: " read name echo "the name is $...
0
votes
0answers
40 views

append to a string in loop not working

I have a ksh script, where I am trying to read from file in a loop and append certain values to each line in the file. It is not working. Below is the code: Code snippet: input="$...
0
votes
1answer
49 views

Process exits unexpectedly when sending to a named pipe

I have two processes and one named pipe. One process is actively reading from the pipe, and one process is sending data to the pipe continously. The command that sends to the pipe is the following :...
0
votes
2answers
230 views

Interpret variables from read in string with shell script [duplicate]

I have a text file which is usually filled with multiple lines which I want to "print" with a while loop. The text inside this file contains variables - my problem is, that these variables are not ...
0
votes
2answers
281 views

How to read stderr from the process running in the background?

I wanna send the daemon into the background and only continue my script execution when the daemon outputs the particular line to the stderr, something among the lines: # Fictional daemon { for x ...
2
votes
1answer
72 views

Using read command to read file by line in Bash doesn't work

I have a text.txt file like this line1 line2 line3 I want to write a script that loops over each line and echo out modified line1 modified line2 modified line3 This is the script which is a very ...
6
votes
3answers
14k views

Read line from file then delete

How can I read a series of lines from a file and then remove each line? Obviously I can read like this: while read -r line; do echo $line done < myfile.txt But if I do this: while read -r ...
16
votes
1answer
1k 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 ...
16
votes
4answers
15k views

Bash: interactive remote prompt

I have a script which connects to a remote server and check if some package is installed: ssh root@server 'bash -s' < myscript.sh myscript.sh: OUT=`rpm -qa | grep ntpdate` if [ "$OUT" != "" ] ; ...
1
vote
2answers
353 views

Cannot read regular file - IO operations block

I'm writing a program that scans through all files in an Android device, looking for a specific string. A few seconds through the process, I get stuck on the following file: /sys/power/wakelock_count ...
2
votes
1answer
49 views

Remove duplicate adjacent lines from file

Say we have file like so: foo1 bar foo2 foo2 bar bar bar foo3 I want it reduced to: foo1 bar foo2 bar foo3 basically removing duplicates only if they are adjacent...I started writing a bash ...
8
votes
4answers
938 views

Bash Read: Reading comma separated list, last element is missed

The output of the command below is weird to me. Why does it not give me back element 5? $ echo '0,1,2,3,4,5' | while read -d, i; do echo $i; done 0 1 2 3 4 I would expect '5' to be returned as well. ...
1
vote
1answer
34 views

read -s gives error via script

I am trying to read a password from user, i used -s silent flag but read -s is not working from the script but it works if i do it manually from terminal. error details project.sh: 3: read: Illegal ...
0
votes
0answers
99 views

Alternative to `while read line` for pipe

I have this: export var=1 kbc get pods -o=json | jq -r '.items[].metadata.name' | while read line; do echo "$line"; done; kbc get pods -o=json | jq -r '.items[].metadata.name' | xargs echo var=$...
0
votes
1answer
60 views

while read loop seems to terminate after the first line, when using two pipes?

#!/usr/bin/env bash set -euo pipefail while read -r line do echo "line via echo:" echo "$line" echo "line via sed:" sed 's/w/f/g' | sed 's/f/zzzzz/g' <<< "$line" done < /dev/...
0
votes
1answer
214 views

Input from readline owerwrites the prompt

I'm trying to create an interactive bash script, where i can call given options from 1-n or just them like commands. It will end up with a simulated prompt and 'read' is used to get the input, ofc. ...
0
votes
2answers
132 views

Why does `read` not pick up all my vars?

Why the following does not print 3 2 1 6 5 4? echo '1 2 3 4 5 6' | while read a b c; do echo result: $c b a; done Wouldn't the first three numbers be read in order, printed in reverse, and then the ...
10
votes
4answers
18k views

Multiple commands during an SSH inside an SSH session

I have a local machine which is supposed to make an SSH session to a remote master machine and then another inner SSH session from the master to each of some remote slaves, and then execute 2 commands ...
3
votes
2answers
135 views

Should the shell read (an script) one character at a time?

While reading an script, the shell will read the script from a file, or from a pipe or possibly, some other source (stdin ?). The input may not be seek able under some corner conditions (no way to ...
5
votes
3answers
50k views

Read lines and match against pattern

I can't figure this out. I need to look at every line in file and check out whether it is matching word which is given in variable I started through command read, but I don't know what am I supposed ...
2
votes
1answer
374 views

Why isn't it possible to read from `stdin` with `read` when piping a script to bash?

I'm not looking for work-arounds or solutions for the issue. I'm fine with it not working like that in bash. I just don't understand why it doesn't work. I'm looking for an in-depth answer why the ...
1
vote
2answers
204 views

read-verification alternative (two prompts and if-then comparison alternative)

I am trying to create a small script for creating simple, all-default Apache virtual host files (it should be used any time I establish a new web application). This script prompts me for the domain....
0
votes
2answers
2k views

Read a file line by line and if condition is met continue reading till end

I want to get user prompted date files which are in two different locations and scp to another server. This is what I have done so far, I am struggling with reading constants from file and ...
0
votes
1answer
552 views

Read command in bash script not executing as a read command and outputting text straight to command line [closed]

I have a bash script that I wrote to automate some commands, and one of the first lines in the script isn't working on the computer that it needs to run on. The code is below #!/bin/bash #some ...
1
vote
1answer
1k views

Split string by space in ZSH

Give this file.txt: first line second line third line This works in bash: while IFS=' ' read -a args; do echo "${args[0]}" done < file.txt To produce first second third That is to say, we ...
7
votes
1answer
308 views

Bash: how can I run `sudo -n true` in the background without interfering with `read`?

I have a long running Bash script that I don't want to run as root, but it needs root access periodically throughout. I solved this by asking for the user for the root password using sudo -v and ...
0
votes
1answer
229 views

Reset terminal after interrupting `read -r -s`

If I run read -r -s INPUT And then interrupt it with Ctrl-C, then the terminal stays in a state where all the input characters are not shown. How can I restore the terminal after such an incident?
1
vote
1answer
389 views

Speed up persistent live usb disk operations

I created a persistent Debian 9 live usb. The persistence is configured with / union. An unexpected consequence, although obvious in hindsight, is the system lags on non-cached reads: holmes@...
0
votes
1answer
36 views

set alias to read variable and then use in second command; only works when I execute them manually

I am with CentOS 7 and I want to bind an alias to launch PostgreSQL shell(psql). I defined this alias and append it in /etc/profile.d/alias: alias psql-local="read -p \"PSQL: enter the DB to connect: ...
4
votes
2answers
560 views

Why bash “read -t 0” does not see input?

My script (should) acts differently, depending on the presence of the data in the input stream. So I can invoke it like this: $ my-script.sh or: $ my-script.sh <<-MARK Data comes... .....
1
vote
2answers
294 views

On backspace, `bash read -e` also deletes same-line printf (preexistent) text

I use printf "input: "; read -e. I type something then I press Backspace. When reaching the last character, this deletes the input: part together with it. Backspace doesn't misbehave if I hadn't typed ...
0
votes
1answer
178 views

Reading multiple files and operating on stored Arrays

I have 2 text files "${LinkP}" and "${QuestionP}. I want to read these files and store each complete line in the respective array, IFS=$'\r\n' GLOBIGNORE='*' command eval "LinkA=($(cat "${LinkP}"))" ...