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
1answer
34 views

Read from stdin and pipe to next command

I would like to read a password from stdin, suppress its output and encode it with base64, like so: read -s|openssl base64 -e What is the right command for that?
0
votes
0answers
35 views

Read numbers from a txt file as the variables, each time for each line

I just began learning to write c-shell scripts. (#! /bin/csh) I have a txt file like this. (contain four parameters of three cases) 1 2 3 4 5 6 7 8 9 10 11 12 And I want to read this file each ...
-1
votes
3answers
110 views

while read loop and variables

I am seeking your council .. as i'm hitting a wall .... in a bash script I'd like to read all of the lines of a given file to an array, and run a set of statements to determine if said args are ...
1
vote
1answer
37 views

How to read keyboard input and assign it to a local variable?

I have this very simple script: #!/bin/bash read local _test echo "_test: $_test" This is the output. $ ./jltest.sh sdfsdfs _test: I want the variable _test to be local only. Is this possible?
0
votes
2answers
97 views

How to print the output of `read -p` to stdout and another file

I was doing echo -n " - This directory is not empty, purge? (Y/N): " | tee -a $mylogs read choice echo "$choice" | tee -a $mylogs but I wanted to try to condense it to: read -p " - This ...
0
votes
0answers
5 views

Sniffing to Signal Coming From a Controller to Raspberry Pi

I am working on a project on Raspberry Pi to send commands to a controller. I am using ttyUSB0 port of the Rpi with RS485 to communicate with controller. Normally, there is a dos program which does ...
0
votes
1answer
55 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 ...
0
votes
2answers
30 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 ``````````````````````````...
-9
votes
1answer
431 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 ...
2
votes
1answer
94 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
568 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 ...
1
vote
1answer
180 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
88 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?...
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
1answer
43 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 ...
1
vote
2answers
40 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
469 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
259 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
77 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
45 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
60 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
665 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 ...
0
votes
2answers
477 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 ...
2
votes
1answer
497 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 ...
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 ...
8
votes
4answers
1k 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. ...
2
votes
1answer
55 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 ...
1
vote
1answer
55 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
118 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=$...
2
votes
1answer
609 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 ...
0
votes
1answer
994 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 ...
2
votes
1answer
2k 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 ...
0
votes
1answer
293 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?
7
votes
1answer
353 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 ...
2
votes
1answer
518 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
37 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
829 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... .....
0
votes
1answer
194 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}"))" ...
3
votes
2answers
160 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 ...
2
votes
1answer
857 views

Does Linux kernel check file permissions on inode or open file description?

I wrote this testing code, and find that this program can always read the file successfully even after I canceled the read permission when running getchar(). #include <stdio.h> #include <...
1
vote
1answer
588 views

How can I make `read` read from stdin? [duplicate]

bash builtin command read is said to accept input from stdin, but why does the following not read in anything? $ printf "%s" "a b" | read line $ printf "%s" "$line" $ Thanks.
1
vote
3answers
166 views

Is there a character as `delim` of `read`, so that `read` reads the entire of a file at once?

In bash manual, about read builtin command -d delim The first character of delim is used to terminate the input line, rather than newline. Is it possible to specify a character as delim of read, ...
3
votes
3answers
454 views

How can I split a string to letters with IFS and read at no space/null, space and at a character -?

I have a string -w o rd. I need to split it to w o r d or to an array for 'w' 'o' 'r' 'd' it doesn't really matter. I have tried the following IFS='\0- ' read -a string <<< "-w o rd" ...
0
votes
1answer
29 views

Why does read from variable give blank new variable? [closed]

I am trying to get a folder name from a stored variable string. When I ran the following path="Folder%20Name/Dir/File" read -d "/" folder < <(echo ${path/\%20/ }) echo "$folder" I am getting a ...
0
votes
1answer
161 views

read issues with ls -i

If I write: ls -i '/home/user/Desktop/file' | awk '{print $1}' I get the inode number of the specified file. I want to make a script that gives me back the inode number of a certain file. If I do: ...
0
votes
1answer
67 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
269 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
1answer
76 views

Is this bash argument substitution?

While studying bash process substitution, I found this: counter=0 while IFS= read -rN1 _; do ((counter++)) done < <(find /etc -printf ' ') echo "$counter files" If I understand correctly,...
1
vote
2answers
211 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....
2
votes
1answer
67 views

What system call does Evince use to open pdf?

I have tried to hook system calls using linux kernel module. However, when I open a pdf file using Evince, I find no open,read and write is used on this specific file, only lstat is used. Here is ...