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
0 answers
16 views

reading into variables from "piped" data [duplicate]

I have a csv (Fieldseparator is the ',') file with data in it and I would have to prepare the csv before reading it (mainly just sort it) into variables. How can I read the sorted stream into ...
roediGERhard's user avatar
0 votes
1 answer
24 views

prompt in git hook?

I'm trying to implement an option to skip a pre-commit hook (which will be considered pass and perform the commit) in a pre-commit hook. Everything is running fine except the prompt which reads an ...
Tomáš Pilný's user avatar
0 votes
0 answers
49 views

Store multiline output in separate variable

A script outputs 3 line output: $ Filename /a/Resource/.Filename.man.markdown .Filename.man.markdown .Filename man.markdown What I want to do I want to store the 3 line output in separate variable, ...
Porcupine's user avatar
  • 1,700
0 votes
0 answers
18 views

Kitty shortcut to escape prompt

Inspired by this answer I have the following mapping in my kitty.conf to escape a stuck command quickly: map ctrl+shift+z send_text normal \x1akill -9 %%\r But for commands which prompt the user such ...
xeruf's user avatar
  • 501
3 votes
1 answer
261 views

"read -r" builtin in bash script acts differently on Mac

I have this script: #!/bin/bash function main { while read -r file; do do_something "$file" done <<< $(find . -type f 2>/dev/null) } function do_something{ echo file:$@...
Brian Holsen's user avatar
0 votes
0 answers
31 views

Why does "read -a" give out error "bad option -a"? [duplicate]

I tried this command : read -a arr <<< "a b c" on centos, it runs well, but on kali (2023.2), it reports "read: bad option: -a" I cannot find out why. Any help please?
Brian Holsen's user avatar
0 votes
1 answer
21 views

how to write a commant for output of a particular group?

Reading file prod1.tpr, VERSION 2019.6 (single precision) Reading file prod1.tpr, VERSION 2019.6 (single precision) Select a group of reference atoms and a group of molecules to be ordered: Group ...
PRAMOD KUMAR's user avatar
5 votes
1 answer
502 views

Why does sending a trapped signal cause `read` to return in POSIX shell but not in Bash?

I was trying to write a shell script that idly waits for a signal in the background. Since the script doesn't take user input I thought of using read to block the script indefinitely while waiting. In ...
yvay's user avatar
  • 53
0 votes
0 answers
84 views

Get coordinates with xdotool upon user click and use them in an automation script

I am trying to prompt the user "Click the confirm button" and use the coordinates as a variable in a script. If the user clicks at 1285 786, I would like to click this coordinate once and ...
PerryJones's user avatar
2 votes
1 answer
162 views

how to use read -s with printf

If I use "read -s" it deletes the existing line and brings the next prompt to the same line as mentioned below. Please let me know any solution to this error. I need to use "-s" ...
dbadmin's user avatar
  • 23
2 votes
2 answers
106 views

how to specify multiple inputs for a command in shell script

I have several fastq files per sample and all of them should be provided at once as an input (as they all belong to one sample, they should NOT be treated independently like in a for loop, as they are ...
Anna1364's user avatar
  • 1,016
1 vote
1 answer
54 views

Why is my entire home backed up?

I wish to back up some of the files located in my home dir. That is simple files at the root of my home and some directories in my home, listed in ~/worthsaving.txt Sample worthsaving.txt: cloud ...
Poor Standard's user avatar
0 votes
1 answer
352 views

Can't capture the output of git pull command in a variable

I run git -C /another-directory pull and I get this error: Your configuration specifies to merge with the ref 'refs/heads/main' from the remote, but no such ref was fetched. Now I want to get that ...
Saeed Neamati's user avatar
0 votes
1 answer
150 views

How does "done < file" work in a while loop?

While trying to learn how to manipulate the content of files in bash, I encountered the following code example: while IFS=, read -r col1 col2 do echo "I got:$col1|$col2" done < myfile....
Mehdi Charife's user avatar
0 votes
1 answer
114 views

Detect whether input is coming from the terminal

I have a shell script that can read from a file or from standard input. Currently, if you don't give it a file or pipe text into it, it starts accepting input at the command prompt. Instead, I would ...
Sildoreth's user avatar
  • 1,822
0 votes
1 answer
97 views

How to capture subshell exit code when assigning subshell output to read? [duplicate]

Consider: $ read -r a <<<$(echo "foo"; exit 1) $ echo $? 0 this returns 0, when I really expect a 1. How can I extract the real exit code from the subshell?
Foo's user avatar
  • 198
0 votes
1 answer
90 views

Printing bash read input character to terminal

Does the bash read command always print the user input on terminal or would I print it myself using echo. For instance I do read -n 1 repl inside a while do loop, reading each character every time.
Vera's user avatar
  • 1,183
0 votes
0 answers
90 views

SSH Connection - Open File to read

im kinda confused, i tried to establish an connection to my server function autoban () { ssh -t xxx.server "sudo su && vi xxx.sh" } by this im trying to connect > go ...
GG STACK's user avatar
2 votes
0 answers
46 views

Why typing long string into read input with color misbehaves? [duplicate]

I can't seem to move my cursor to the beginning of colored read input when I'm typing a really long string. This below gif shows exactly that, the cursor just stuck on there and I can't move it to ...
Liso's user avatar
  • 121
1 vote
0 answers
171 views

zsh: read line without clearing screen below prompt while allowing user to use arrow keys to make edit in middle of line

Using Bash tput cup 0 0; read -e -p "Enter input: " userinput works well for getting a line of user input: It does not clear screen below the prompt It allows user to use arrow keys to go ...
codepoet's user avatar
  • 566
0 votes
0 answers
33 views

Distribute subcommands over head command to avoid writing same words twice?

I would like to try to write this command: while read -r repo; do gh repo delete $repo; done <<< $(gh repo list --no-archived) which basically cleans up my GitHub and deletes everything that ...
hmltn's user avatar
  • 143
0 votes
1 answer
120 views

How to use two newline characters as delimiter when reading input using read

The following command: $ read input hello \ > world $ echo "$input" allows me to enter multiline input by using the backslash character. I'm now looking to change this to allow the ...
Foo's user avatar
  • 198
2 votes
1 answer
582 views

How to read multiline input in bash

I have this script: #!/usr/bin/env bash main() { while true; do read -r -ep "> " input history -s "$input" echo "$input" done } main which works well ...
Foo's user avatar
  • 198
-3 votes
2 answers
268 views

Why this program can not read text file in struct? [closed]

Here is my a.txt file which is of three lines. It does not contain any extra spaces or any non printable characters: David Joans 018976 David12 Here is my code in C to read this file where I have ...
Anup Adhikari's user avatar
0 votes
1 answer
68 views

How does the Kernel implement synchronisation techniques on file access

I've read that the kernel implements synchronisation mechanisms when accessing files. For example, if we try and write or read to a file in the file system using read() or write() from different ...
Engineer999's user avatar
  • 1,121
0 votes
1 answer
25 views

Echo'ing the variable muliple times while reading the variable values from a file

I am trying to write a bash script which would read values from a file and echo out the values. But for what ever reason it is not working correctly. My first file is having the below values Alts Risk ...
ranjit abraham's user avatar
0 votes
4 answers
267 views

Read from file; and execute its content line by line; terminate at first error [closed]

I am reading the content of a file do.sh using the bash command line structure. I want to execute each line of this file, line by line, so that, later, I can add some text to the script which can ...
Amit Kr. Ratewal's user avatar
0 votes
1 answer
61 views

How can I reinstall the "read" command? [closed]

About half hour before posting this, I ran the autoclean and autoremove commands. A few minutes after running the commands, I ran a script that I've been using for months, there are no issues with it. ...
Lee's user avatar
  • 85
0 votes
1 answer
51 views

Bash readline eats everything if piped

I have a simple script. # test.sh read -p ">> " user read -p ">> " -n1 yes echo echo "user: $user" echo "yes: $yes" When executed as bash test....
Marko Todoric's user avatar
2 votes
1 answer
187 views

Specify a Keypress as a variable for "if" command

Before continuing, please bear in mind that I am aware that I could configure keyboard shortcuts through the settings menu, but that would not be of use for my end goal. I'm trying to create a simple ...
Lee's user avatar
  • 85
0 votes
1 answer
118 views

Unable to transfer file content via `read` command

I am trying read the contents of file into an array for further processing later. I am using read command for filling the array values. The following is a portion of my code that is causing the error. ...
G.MAHESH's user avatar
1 vote
1 answer
315 views

How to separate long string into a string array with IFS and read, or any other method

I have a long line that comes as output from a git command: a=$(git submodule foreach git status). It looks like this: a = "Entering 'Dir1/Subdir' On branch master Your branch is up to date with '...
Zaida's user avatar
  • 133
3 votes
1 answer
239 views

Bash variable truncated when passed into ffmpeg

I have an album of 11 .flac audio files. (edit: since this issue has been resolved, it's now clear that the precise names and content of the files are irrelevant, so I've renamed them): > find . -...
colmbaston's user avatar
0 votes
1 answer
85 views

Parse huge amounts of files efficiently

I have a folder that holds hunderds of thousands of files called hp-temps.txt. (There are also tons of subfolders) The content of these files looks like this for example: Sensor Location ...
Lumnezia's user avatar
  • 111
0 votes
4 answers
206 views

Bash: interactively enter and save large html block into a variable from the terminal

This is simple #!/bin/bash echo "What is your name?" read name echo "Your name is: $name" But what if I don't want to treat a name but a large HTML code block with nested tags and ...
pastic's user avatar
  • 111
0 votes
1 answer
90 views

Why does the execution of these functions break out of this while loop?

The following script is meant to trim all media files in the current working directory. #!/usr/bin/bash trimmer() { of=$(echo "${if}"|sed -E "s/(\.)([avimp4kvweb]{3,3}$)/\1trimmed\.\...
John Smith's user avatar
0 votes
1 answer
62 views

How to "properly" read remote sshd server version with bash

I'm trying to read remote SSHD server version with bash without installing an extra tool : $ cat < /dev/tcp/x.y.z.t/22 SSH-2.0-OpenSSH_7.2 FreeBSD-20160310 ^C CTRL+C is needed, so I tried to read ...
SebMa's user avatar
  • 1,991
0 votes
0 answers
28 views

Why is my script misbehaving sometimes? [duplicate]

I have created a script that can split an audio file into smaller files via ffmpeg using timestamps, and another script which can take in timestamps & names in batches. My use for this script ...
Cestarian's user avatar
  • 2,011
2 votes
3 answers
1k views

Trying to find complete string values from one file based on another file using AWK

Hello I have 2 files with the first file containing a few values for example powershell vectormaps JuniperSA and the second file containing values and and ID appid uid SplunkforSnort 340 powershell ...
ranjit abraham's user avatar
0 votes
0 answers
97 views

Problem with read command while searching txt file line by line

I am trying to do a simple dictionary of words inserted by user which are collected in txt file and then the function to learn them. Words in two different languages are seperated by a chosen ...
mck's user avatar
  • 1
0 votes
1 answer
344 views

Looping through variables which is an output of another command

Hello I am learning Scripting here. I am trying to write a simple script using the 'for' loop. I have hundreds of folders in a folder called user. if i run this command i get a list of folders that i ...
ranjit abraham's user avatar
2 votes
2 answers
706 views

Reading from two fifos in Bash

I'm trying to read from two fifos (read from one, if there's no content read from the other, and if there's no content in neither of both try it again later), but it keeps blocking the process (even ...
Roger Miranda Perez's user avatar
1 vote
0 answers
220 views

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

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 ...
user525799's user avatar
0 votes
2 answers
2k 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 ...
ranjit abraham's user avatar
4 votes
2 answers
4k 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 ...
Fajela Tajkiya's user avatar
0 votes
0 answers
203 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 ...
John R's user avatar
  • 115
3 votes
1 answer
76 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. ...
Sir Muffington's user avatar
-1 votes
1 answer
200 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; ...
jonathan's user avatar
  • 101
0 votes
1 answer
623 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 ...
smut's user avatar
  • 3
1 vote
1 answer
829 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 &...
Erwann's user avatar
  • 605

1
2 3 4 5
8