Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
0
answers
82
views
In "read", why does the cursor does not move to the next input line when there is 1 character more than there are columns?
I have noticed that when providing input to `read`, both Bash's and Dash's, the cursor does not move to the next line if the current line contains 1 character more than there are columns. In MATE Terminal, GNOME Terminal and LXTerminal, the cursor disappears. In xterm and the virtual console the cur...
I have noticed that when providing input to
read
, both Bash's and Dash's, the cursor does not move to the next line if the current line contains 1 character more than there are columns. In MATE Terminal, GNOME Terminal and LXTerminal, the cursor disappears. In xterm and the virtual console the cursor stays in the last column.
If the current line contains 2 character more than there are columns, then in all the aforementioned terminals and the console, the cursor appears on the next input line, in the second column, after the excessive character.
This behavior can be seen in Bash with
read -p "$( x="$( tput 'cols' )" ; for (( y = 0 ; y < x ; ++y )) ; do echo -n 'x' ; done )"
I don't know if the command works in Dash. This command prints the prompt in read
long enough to fill the first line for input with the character "x" until the last column, included (read
waits for further input, so you need to control-d
to return to the shell). Notice that the cursor has disappeared from the terminal (or console).
On the other hand, we see that making the prompt in read
1 character longer causes the cursor to appear on the next line. It can be seen with just changing the 0
in the previous command to -1
, like
read -p "$( x="$( tput 'cols' )" ; for (( y = -1 ; y < x ; ++y )) ; do echo -n 'x' ; done )"
Now we print 1 character more that there are columns, the line wraps, and the cursor is shown.
The behavior that I would expect is that the cursor moves to the next line if the current line contains 1 character more than there are columns (i.e. the cursor never disappears or stays in the last column).
**So, why does the cursor not move? Is it expected behavior? What program or library causes it?**
decision-making-mike
(179 rep)
Jul 20, 2025, 05:55 PM
0
votes
1
answers
72
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 # The response looks like ^[[n;mR - where n = row, m = col read -s -d\[ garbage # Read the response silently, discarding the...
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
# The response looks like ^[[n;mR - where n = row, m = col
read -s -d\[ garbage # Read the response silently, discarding the first part of the response, leaving n;mR
read -s -d ';' row # Read some more, silently, until we get to the character ';', storing what we read in the variable "row"
read -s -d R col # Read some more, silently, until we get to the character 'R', storing what we read in the variable "col"
echo "The (row,col) coords are ($row,$col)"
If I run echo -ne "\033[6n"
at a shell prompt, I get kind of what the comments say I'll get, but not exactly:
$ echo -ne "\033[6n"
^[[11;1R$ ;1R
If I put that in a script (I'll call it "splurt.sh"), and run the script, the results are the same:
#!/usr/bin/env bash
echo -ne "\033[6n"
echo
$ ./splurt.sh
^[[16;1R$ ;1R
So at this point, I just accept that the line works, even if it's not displaying as I would expect it to.
But then comes the next line:
read -s -d\[ garbage # Read the response silently, discarding the first part of the response, leaving n;mR
I kind of understand that "read" reads input from the console (keyboard, usually, I would think), but somehow it seems to be reading from the console's monitor?
I understand the "-s" means to read the console silently, but I don't quite comprehend that. I put this into my short script:
#!/usr/bin/env bash
echo -ne "\033[6n"
read -s -d\[ garbage
echo
and I get:
$ ./splurt.sh
$ 25;1R
If I leave out the "-s", I get:
$ ./splurt.sh
^[[27;1R
$ 27;1R
So I can see that the "-s" does prevent the echo of "^[[27;1R" to the screen, but I don't grok that, because I thought the echo -n e "\033[6n"
had already printed that out to the screen (although apparently not, because I don't see it until the "read" reads it?).
I do understand (finally! I understand something!) that the "-d" only reads up to the specified delimiter (usually a newline, as I understand it, unless specified by the "-d"), and that what gets read is placed into the variable "garbage" (which is henceforth ignored), but I don't understand how "\[" causes the read to go all the way through "^[[", instead of stopping at "^[", to leave "[27:1R" instead of what it actually leaves of "27:1R".
And then the rest of the script I have a fairly good grip on, methinks.
Anyone want to take a stab at helping me to understand better what's going on? Thanks!
user153064
(13 rep)
Jul 8, 2025, 01:28 PM
• Last activity: Jul 8, 2025, 08:05 PM
0
votes
2
answers
44
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 I know which? if(???) { read(fd, .......); } else { write(fd, ......); } close(fd); (I need that close, because if I am...
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 I know which?
if(???) {
read(fd, .......);
} else {
write(fd, ......);
}
close(fd);
(I need that close, because if I am writing I need to send an EOF to the other end. And any writer will send a single line through and close, so I also need to close if I read.)
What do I put instead of the ??? to figure out what the other end did?
Is non-blocking and
select()
my only option? Is there a way to inspect fd
and see if it's ready for reading or writing?
Ariel
(117 rep)
May 30, 2025, 06:30 PM
• Last activity: May 31, 2025, 06:15 AM
0
votes
1
answers
2212
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 the output displayed on the terminal in real time. For the sake of simplicity let say each of these...
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 the output displayed on the terminal in real time.
For the sake of simplicity let say each of these for loops represents one of my background scripts (The outputs contain color codes btw.):
for i in {0..1000} ; do
echo -e "\033[0;31mHello world\033[0m $i"
sleep 1
done &
for i in {0..1000} ; do
echo -e "\033[0;34mHello world\033[0m $i"
sleep 1
done &
My first idea was to redirect all the output of the background scripts into a file and then use the
read
command to get a search query and pass it to grep
like so:
for i in {0..1000} ; do
echo -e "\033[0;31mHello world\033[0m $i"
sleep 1
done >> ./output.txt 2>&1 &
for j in {0..1000} ; do
echo -e "\033[0;34mHello world\033[0m $j"
sleep 1
done >> ./output.txt 2>&1 &
while true ; do
read -p "Search: " query
clear
cat ./output.txt | grep "$query"
done
But there are several issues with that.
**Update problem**: The output won't update when the output.txt
file changes. So you have to repeatedly search again to get up-to-date results.
**Color code problem**: If I search for 3
it will print all lines because the color codes contains a 3
. I could of course completely filter out the colors like so: cat ./output.txt | sed 's/\x1b\[[0-9;]*m//g' | grep "$query"
, but I don't want to lose the color in the final output so it's not that easy.
**Disappearing input problem**: Even if I'd manage to get new output to be printed in real time after hitting enter for a search, the user won't be able to type (or see, to be more accurate) his/her next search properly. I would like the filter text the user is typing to always be visible.
Any ideas how this could be accomplished?
Forivin
(1193 rep)
Oct 11, 2019, 09:38 AM
• Last activity: May 26, 2025, 08:03 AM
9
votes
4
answers
22590
views
How to read the user input line by line until Ctrl+D and include the line where Ctrl+D was typed
This script takes the user input line after line, and executes `myfunction` on every line #!/bin/bash SENTENCE="" while read word do myfunction $word" done echo $SENTENCE To stop the input, the user has to press `[ENTER]` and then `Ctrl+D`. How can I rebuild my script to end only with `Ctrl+D` and p...
This script takes the user input line after line, and executes
myfunction
on every line
#!/bin/bash
SENTENCE=""
while read word
do
myfunction $word"
done
echo $SENTENCE
To stop the input, the user has to press [ENTER]
and then Ctrl+D
.
How can I rebuild my script to end only with Ctrl+D
and process the line where Ctrl+D
was pressed.
user123456
(5258 rep)
Oct 13, 2016, 06:58 PM
• Last activity: Apr 11, 2025, 05:29 AM
15
votes
4
answers
8159
views
read command in zsh throws error
In zsh, running the command `read -p 'erasing all directories (y/n) ?' ans`, throws the error, read: -p: no coprocess But in bash, it prints a prompt. How do I do this in zsh?
In zsh, running the command
read -p 'erasing all directories (y/n) ?' ans
, throws the error,
read: -p: no coprocess
But in bash, it prints a prompt. How do I do this in zsh?
user93868
Apr 24, 2015, 12:54 PM
• Last activity: Mar 7, 2025, 12:57 PM
0
votes
1
answers
88
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, ```sh $ mkfifo pipe $ cat pipe & # read from the pipe in the background $ cat > pipe # write to the pipe line1 line2 ... ``` If I then stop the reader process, the writer process die...
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 > pipe # write to the pipe
line1
line2
...
If I then stop the reader process, the writer process dies because of the SIGPIPE the reader process sent when stopping.
I don't want this to happen. If the writer tries writing to the pipe *before* a reader appears, the writer blocks and waits for a reader. I want behavior like this. If the reader closes the pipe, the writer should block and wait for a new reader.
Likewise, if I stop the writer process, the reader process closes because it sees an EOF (or rather, a 0 byte read). I would also like for it to block until a new writer appears, instead.
Does cat
have a flag for doing this? If not, this is is probably a pretty simple C program.
Joseph Camacho
(109 rep)
Jan 30, 2025, 07:00 PM
• Last activity: Jan 30, 2025, 09:21 PM
1
votes
1
answers
47
views
Why read process doesn't show up in ps -ef
I open two terminal windows. In one, I run: ```none $ read foo ``` I don't press RETURN , so `read` is blocking. In the other terminal window, I search for the process: ```none $ ps -ef | grep foo user 95292 94814 0 08:04 pts/11 00:00:00 grep foo ``` However, the running `read` process is not showin...
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 0 08:04 pts/11 00:00:00 grep foo
However, the running read
process is not showing up? What am I doing wrong?
Ruben P. Grady
(31 rep)
Jan 21, 2025, 12:07 AM
• Last activity: Jan 21, 2025, 12:24 AM
1
votes
1
answers
101
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 $file"; rm "$file"; done; background.bundle.js 964.bundle.js background.bundle.js.LICENSE.txt ... META-I...
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 $file"; rm "$file"; done;
background.bundle.js
964.bundle.js
background.bundle.js.LICENSE.txt
...
META-INF/manifest.mf
META-INF/mozilla.sf
META-INF/mozilla.rsa
^D
rm background.bundle.js
rm: remove regular file ‘background.bundle.js’? $
$
(Notice the ^D at the end)
As shown, after issuing the ^D (end-of-file), the sponge command sends the entire output to the while loop, and rm is invoked for each file separately. However, what happens is that it gets invoked once for background.bundle.js, asks for confirmation, and without allowing me the opportunity to enter anything, the loop exits prematurely. This leaves the prompt character ($) without the necessary newline that should follow it, indicating an abrupt end to the loop.
I am looking to fix this issue without resorting to temporary files. I want to manage file input using exec so that the loop reads from a different input stream, leaving standard input available for rm to read the user’s confirmation. How can I redirect sponge output and read input to a specific file descriptor for this purpose?
ychaouche
(1033 rep)
Nov 14, 2024, 05:56 PM
• Last activity: Nov 18, 2024, 11:25 AM
0
votes
0
answers
55
views
Why command `cat test.log |while read line; do echo $line ; done` would compress whitespace?
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 |while read line; do echo $line ; done and It returns 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 a Wired,something was truncated.What happend?
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 |while read line; do echo $line ; done
and It returns
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 a
Wired,something was truncated.What happend?
傅继晗
(101 rep)
Nov 6, 2024, 04:46 AM
• Last activity: Nov 6, 2024, 07:44 AM
6
votes
3
answers
3466
views
Why must I put the command read into a subshell while using pipeline
The command `df .` can show us which device we are on. For example, me@ubuntu1804:~$ df . Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdb1 61664044 8510340 49991644 15% /home Now I want to get the string `/dev/sdb1`. I tried like this but it didn't work: `df . | read a; read a b; echo "...
The command
df .
can show us which device we are on. For example,
me@ubuntu1804:~$ df .
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb1 61664044 8510340 49991644 15% /home
Now I want to get the string /dev/sdb1
.
I tried like this but it didn't work: df . | read a; read a b; echo "$a"
, this command gave me an empty output. But df . | (read a; read a b; echo "$a")
will work as expected.
I'm kind of confused now.
I know that (read a; read a b; echo "$a")
is a subshell, but I don't know why I have to make a subshell here. As my understanding, x|y
will redirect the output of x
to the input of y
. Why read a; read a b; echo $a
can't get the input but a subshell can?
Yves
(3401 rep)
Dec 1, 2020, 02:58 AM
• Last activity: Jul 23, 2024, 06:23 PM
-2
votes
1
answers
583
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 echo Yes else echo No goto?!? jumpto?!? urandom line fi it reads from urandom and ask if this ok, if yes the script end. if...
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
echo Yes
else
echo No
goto?!? jumpto?!? urandom line
fi
it reads from urandom and ask if this ok, if yes the script end.
if not yes, i will read and ask again - how to do this?
do i need goto? or jumpto or anything other?
user447274
(539 rep)
Jul 10, 2024, 08:32 AM
• Last activity: Jul 10, 2024, 01:40 PM
-2
votes
1
answers
114
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: ``` grep -ir $(read) /etc/nginx/ ``` What's the correct way to use `read` inside argument?
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:
grep -ir $(read) /etc/nginx/
What's the correct way to use read
inside argument?
palmasd1
(127 rep)
Jun 2, 2024, 01:42 PM
• Last activity: Jun 2, 2024, 05:47 PM
0
votes
1
answers
179
views
Add a numerical value to a variable while reading a file in bash in loop
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 alsv2_prod_app,30 alsv2_qa_app,15 My expected output should be as below. the third value is second valu...
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
alsv2_prod_app,30
alsv2_qa_app,15
My expected output should be as below. the third value is second value + 1096
agile_prod_toolkit,30,1126
alsv2_prod_app,30,1126
alsv2_qa_app,15,1111
What i have tried is
while IFS="," read line ret;do
value=$ret+1095
print $line,$ret,$value
done < final_original
But this does not seem to work. can someone please tell me what i am doing wrong here?
The output that i am getting here when i run the above command is like this
agile_prod_toolkit,30,30+1095
alsv2_prod_app,30,30+1095
alsv2_qa_app,15,15+1095
ranjit abraham
(145 rep)
May 23, 2024, 12:51 AM
• Last activity: May 23, 2024, 01:30 AM
1
votes
2
answers
1324
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 | myscript.sh This works as long as some-random-program sends its output to stdout. However, if the script sen...
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 | myscript.sh
This works as long as some-random-program sends its output to stdout.
However, if the script sends output to stderr, then my script sees no output. I know I can do this:
some-random-program 2>&1 | myscript.sh
**My question is this:** is there a way to get myscript.sh to read from stderr so that the "2>&1" (or any variation of it) *is not necessary*? I thought I could do this:
while read -r -a line
do
... parse $line in some way
done < /dev/stderr
But that didn't work. The script never sees any input.
lord_nimon
(141 rep)
May 21, 2024, 09:24 PM
• Last activity: May 21, 2024, 10:52 PM
0
votes
2
answers
7728
views
Loop over columns and store values to associative arrays
I've got a text file containing two columns, like so: 26 0.000342231 27 0.000342231 28 0.000684463 29 0.00136893 30 0.00102669 31 0.00308008 32 0.00308008 33 0.00444901 34 0.00718686 35 0.00718686 36 0.0109514 37 0.0123203 ... I'd like to loop over the text file and store each columns value to an as...
I've got a text file containing two columns, like so:
26 0.000342231
27 0.000342231
28 0.000684463
29 0.00136893
30 0.00102669
31 0.00308008
32 0.00308008
33 0.00444901
34 0.00718686
35 0.00718686
36 0.0109514
37 0.0123203
...
I'd like to loop over the text file and store each columns value to an associative array - something like a dictionary.
If possible I'd like to keep data types of values in each column (int and float).
For a calculation I then need to sum up 2nd column's values for a particular interval till the end of the file, e.g. "sum up 29's (1st column) associated value (0.00136893) down to the last associated value"
What's the best way to do so? Bash and python solutions are most welcome!
Aliakbar Ahmadi
(203 rep)
Aug 11, 2015, 10:18 AM
• Last activity: Apr 20, 2024, 03:09 PM
0
votes
1
answers
118
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 ``` {.bash .numberLines} find . -type f -iname '*AlbumArt*' -print0 | sort -z \ | xargs -0 -I "{}" bash -c ' find...
### 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
{.bash .numberLines}
find . -type f -iname '*AlbumArt*' -print0 | sort -z \
| xargs -0 -I "{}" bash -c '
find "$(dirname "${1}")" -maxdepth 1 -iname "*cover*.jpg" -print0' _ "{}" \; \
| uniq -z | xargs -0 -I "{}" bash -c '
ls -la "$(dirname "${1}")"/*.jpg;' _ "{}" \;
## What I actually want to do?
I want to list all folder that contain iname *cover*.jpg
and iname*AlbumArt*
and list the size of each image file in that folder and also open nautilus so that I can manually inspect those images in that folder (as I want to delete some extra files), this I want to do one folder at a time. So for each output of xargs I want to do ls -la
and open nautilus and wait for nautilus to close so I added nautilus "${1}"; read -r -p "Press any key to continue" Continue;
to above:
{.bash .numberLines}
find . -type f -iname '*AlbumArt*' -print0 | sort -z \
| xargs -0 -I "{}" bash -c '
find "$(dirname "${1}")" -maxdepth 1 -iname "*cover*.jpg" -print0' _ "{}" \; \
| uniq -z | xargs -0 -I "{}" bash -c '
ls -la "$(dirname "${1}")"/*.jpg; nautilus "${1}"; read -r -p "Press any key to continue" Continue;' _ "{}" \;
```
This works but it won't stop for user input as per read -r -p "Press any key to continue" Continue;
i.e. several windows of nautilus opens! But I want to open only one nautilus at a time so I want xargs to wait after each execution of the line.
What should I do to make xargs wait for user input after each line of execution?
Porcupine
(2156 rep)
Mar 31, 2024, 02:37 PM
• Last activity: Apr 1, 2024, 06:51 AM
0
votes
1
answers
51
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":"Network Rule 1", "description":"Network Rule 1", "from":["internal"], "source":["any"], "user":["domain\\network_user1"],...
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":"Network Rule 1", "description":"Network Rule 1", "from":["internal"], "source":["any"], "user":["domain\\network_user1"], "to":["external"], "destination":["host.example.com","10.1.2.1"], "port":["8443","22"],
"name":"Network Rule 2", "description":"Network Rule 2", "from":["internal"], "source":["any"], "user":["domain\\network_user2"], "to":["external"], "destination":["host.example.com","10.2.1.1"], "port":["23","25"],
"name":"Network Rule 3", "description":"Network Rule 3", "from":["internal"], "source":["any"], "user":["domain\\network_user3"], "to":["external"], "destination":["host.example.com","10.3.4.1"], "port":["80","143"],
I'm trying to append a few more fields (all the same) to the list; these fields would be something like...
"access":"allow", "time":"00:00:00-23:59:59", "notify":"yes"
The final output should look like this:
"name":"Network Rule 1", "description":"Network Rule 1", "from":["internal"], "source":["any"], "user":["domain\\network_user1"], "to":["external"], "destination":["host.example.com","10.1.2.1"], "port":["8443","22"], "access":"allow", "time":"00:00:00-23:59:59", "notify":"yes"
"name":"Network Rule 2", "description":"Network Rule 2", "from":["internal"], "source":["any"], "user":["domain\\network_user2"], "to":["external"], "destination":["host.example.com","10.2.1.1"], "port":["23","25"], "access":"allow", "time":"00:00:00-23:59:59", "notify":"yes"
"name":"Network Rule 3", "description":"Network Rule 3", "from":["internal"], "source":["any"], "user":["domain\\network_user3"], "to":["external"], "destination":["host.example.com","10.3.4.1"], "port":["80","143"], "access":"allow", "time":"00:00:00-23:59:59", "notify":"yes"
When I try to append the fields in a loop, my double backslash disappears both when running the following command in a script and directly in the shell.
while read LINE; do
echo $LINE \"access\":\"allow\", \"time\":\"00:00:00-23:59:59\", \"notify\":\"yes\"
done completed_list.csv
Instead, this results in the following example where the username double backslash has disappeared.
"name":"Network Rule 1", "description":"Network Rule 1", "from":["internal"], "source":["any"], **"user":["domain\network_user1"]**, "to":["external"], "destination":["host.example.com","10.1.2.1"], "port":["8443","22"], "access":"allow", "time":"00:00:00-23:59:59", "notify":"yes"
I'm guessing something is wrong with using echo to print the whole line, but what is a way to work around that?
Thank you in advance.
vxla
(11 rep)
Mar 28, 2024, 05:41 PM
• Last activity: Mar 28, 2024, 06:00 PM
1
votes
1
answers
402
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. - Input is copy/pasted from PostMan, its an S3 signed upload URL - If I try and delete a few chars from the end...
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.
- Input is copy/pasted from PostMan, its an S3 signed upload URL
- If I try and delete a few chars from the end (after pasting) I am only able to manually type as many chars as I deleted
- I tried using the -n
option to no avail (nothing gets read into the variable)
How can I read a long input? ~1500 chars
SoonGuy
(131 rep)
Mar 14, 2024, 01:36 PM
• Last activity: Mar 14, 2024, 06:13 PM
0
votes
1
answers
203
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, and you must tell read to use stdin as in `read -u0`. But then if I change it to -u0 (which makes...
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, and you must tell read to use stdin as in read -u0
.
But then if I change it to -u0 (which makes previous case work) and execute my script without redirecting tty, it breaks the script, it simply does not behave as executing it without -u0.
**EDIT**: After debugging, it seems the issue is simply that after using -u0, the -k1 option does not read a single char and stops anymore. read works in this case as without -k, simply buffering all input and saving it as soon as an EOL arrives
**EDIT2**: After more debugging I know it's something related to the raw mode not working with -u0. If I add stty raw/cooked before my read then it works (except enter keystroke is now handled with \r not \n), but then when I execute it with non-tty stdin it breaks.
Is there any way to make both modes compatible?
Indeed I would like to understand why the script behaves different at all, if either I read with -u0 or not, fd0 is by default the same as /dev/tty
Whimusical
(285 rep)
Mar 11, 2024, 12:32 AM
• Last activity: Mar 11, 2024, 07:12 PM
Showing page 1 of 20 total questions