Skip to main content

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
-2 votes
1 answer
102 views

Linux Bash Script - Yes or No - read answer

little script #!/bin/sh cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 4 printf 'do you like this? (y/n)? ' read answer if [ "$answer" != "${answer#[Yy]}" ] ;then ...
user447274's user avatar
-2 votes
1 answer
77 views

Is it possible to read user input with no extra variables?

I want to grep an IP address inside Nginx configuration files. I want to input the IP address with the read command, but I don't want to store input in an additional variable. So I want something like:...
palmasd1's user avatar
  • 125
0 votes
1 answer
31 views

Add a numerical value to a variable while reading a file in bash in loop [duplicate]

I have a file with the following values. I am trying to read from the file and add 1096 to the last value and generate the output on screen. My original file looks like this. agile_prod_toolkit,30 ...
ranjit abraham's user avatar
1 vote
2 answers
82 views

Is it possible to read from stderr in a bash script?

I have a bash script like this: #!/bin/bash while read -r -a line do ... parse $line in some way done This script is executed by piping the command from another program: some-random-program | ...
lord_nimon's user avatar
0 votes
1 answer
75 views

Find - xargs, for every line open a new shell and execute a command and wait for user to exit that shell

Following works Task: List all folders that contain file of iname *AlbumArt* that also contain iname *cover*.jpg, and for each of those folder list all jpg files with size find . -type f -iname '*...
Porcupine's user avatar
  • 2,056
0 votes
1 answer
33 views

Double backslash disappears when printed in a loop

I have a script that joins together various lists of data fields which then needs to have a few more columns added. The file generated looks like this: $ cat compiled.csv "name":"...
vxla's user avatar
  • 11
1 vote
1 answer
61 views

Unable to read more than 1024 chars on ZSH + MacOS

Trying to read a long input into a variable from ZSH on MacOS. echo "URL: " read URL input is always truncated to 1024 chars... if I try and type additional chars nothing happens. ...
SoonGuy's user avatar
  • 131
0 votes
1 answer
67 views

Issue of read with -u and -k in zsh

I am developing a zsh script that uses read -k. If I execute my script like this (echo a | myscript), it fails to get input. Apparently it is due to the fact that -k uses /dev/tty as stdin invariably, ...
Whimusical's user avatar
2 votes
3 answers
865 views

Execute copy commands from file

I have a DE_CopyOldToNew.txt file with a whole bunch of copy commands for copying old file names to new file names. The file contains rows like : cp /migrationfiles/Company\ Name\ GmbH/2014.138_Old\ ...
Rico Strydom's user avatar
0 votes
0 answers
158 views

read single line from stdin and write to a file

Is there a way in bash to read a single line from stdin and write directly to a file? Something like: t="$(mktemp)" while true do [read single line from stdin] > "${t}" [...
fuumind's user avatar
  • 449
1 vote
2 answers
121 views

How do I use a nonstandard file descriptor for reading a file into an array with mapfile?

mapfile -t -u 7 arr < textfile gives me bash: mapfile: 7: invalid file descriptor: Bad file descriptor Other, more verbose, methods of reading files line-by-line do allow for such descriptor, e.g. ...
John Smith's user avatar
2 votes
1 answer
490 views

Why does `read` fail saying "read error: 0: Resource temporarily unavailable"?

script #!/bin/bash -- # record from microphone rec --channels 1 /tmp/rec.sox trim 0.9 band 4k noiseprof /tmp/noiseprof && # convert to mp3 sox /tmp/rec.sox --compression 0.01 /tmp/rec.mp3 ...
Pound Hash's user avatar
2 votes
2 answers
618 views

pipe the read command?

I'm trying to pipe a string with special characters (e.g. HG@eg3,l'{TT\"C! to another command (termux-clipboard-set) with the read program. It seems that read was designed to create a temporary ...
Daniel Krajnik's user avatar
0 votes
2 answers
98 views

How to catch newlines in user input

I want to do something with user input to use in grep. Like, instead of uin="first\nsecond\n" printf $uin | grep d which outputs second, I want to have the user input it, like read uin ...
user14094230's user avatar
0 votes
0 answers
50 views

Circular pipe situation

More of an academic/theory question - say I have process A piping into process B: A | B normally, the way pipes are designed, is if process A dies, the pipeline will gracefully shutdown. However, if ...
Alexander Mills's user avatar
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
1 vote
1 answer
145 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
3 votes
1 answer
495 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
22 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
622 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
2 votes
1 answer
341 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
168 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,036
1 vote
1 answer
57 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
1k 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
275 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
269 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,904
0 votes
1 answer
217 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
  • 232
0 votes
1 answer
219 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
2 votes
0 answers
65 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
  • 131
1 vote
0 answers
354 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
  • 596
0 votes
0 answers
34 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 ...
Julius Hamilton's user avatar
0 votes
1 answer
636 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
  • 232
2 votes
1 answer
1k 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
  • 232
-3 votes
2 answers
484 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
190 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,171
0 votes
1 answer
36 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
729 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
81 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
  • 97
0 votes
1 answer
66 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
414 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
  • 97
0 votes
1 answer
196 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
578 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
369 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
246 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
314 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
115 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
83 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
  • 2,209
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,071
2 votes
3 answers
2k 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

1
2 3 4 5
8