Questions tagged [read]
`read` is a shell utility used for reading strings from the standard input stream, or from a file descriptor.
374 questions
2
votes
1
answer
63
views
Make `set -o vi` vim cursor reflect editing mode when in `read`
I have a script read.sh:
read -ei "hello world"
eval $REPLY
Upon executing chmod +x read.sh and then running ./read.sh, I notice that pressing Esc followed by b or w jumps between the ...
5
votes
1
answer
272
views
Differences between bash and fish read command
In bash, the following command
printf 'foo bar\n' | { read a b; printf '<%s> <%s>\n' $a $b; }
produces the output
<foo> <bar>
In fish, the following command
printf 'foo ...
0
votes
1
answer
126
views
Need Help Understanding script that reads output of cursor position ANSI escape code
I have this code, which does what I want, but I don't entirely understand it:
#!/usr/bin/env bash
echo -ne "\033[6n" # Ask the terminal to print out the cursor's position
...
0
votes
2
answers
99
views
when opening a FIFO for reading+writing, and blocking - how to tell if other side opened for reading or writing?
If I open a fifo for reading+writing in blocking mode:
fd = open("foo", "O_RDWR");
Then it blocks until someone on the other end opens it for either reading or writing. But how do ...
0
votes
1
answer
131
views
How can I make writes to named pipe block if the reader closes, and vice versa?
Right now if I write to a name pipe and then close the reader, the writer gets a SIGPIPE and then exits. For example,
$ mkfifo pipe
$ cat pipe & # read from the pipe in the background
$ cat > ...
1
vote
1
answer
68
views
Why read process doesn't show up in ps -ef
I open two terminal windows. In one, I run:
$ read foo
I don't press RETURN, so read is blocking. In the other terminal window, I search for the process:
$ ps -ef | grep foo
user 95292 94814 ...
1
vote
1
answer
111
views
rm prompt not working when invoked from a piped loop
I am trying to remove files from a directory by pasting their names into a while loop that will simply rm each item from the list of files given to it.
$ sponge | while read file; do echo "rm $...
0
votes
0
answers
70
views
Why command `cat test.log |while read line; do echo $line ; done` would compress whitespace? [duplicate]
I have a file named "test.log" with contents:
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kthreadd]
Then I use while-read command to process it:
cat test.log |...
-2
votes
1
answer
739
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
...
-2
votes
1
answer
143
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:...
0
votes
1
answer
219
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
...
1
vote
2
answers
2k
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 | ...
0
votes
1
answer
136
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 '*...
0
votes
1
answer
57
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":"...
1
vote
1
answer
464
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.
...