The tag has no usage guidance.

learn more… | top users | synonyms

2
votes
2answers
59 views

Split words from `read` and store to array?

How can I take input from read, split the words up by spaces, and then put those words into an array? What I want is: $ read sentence this is a sentence $ echo $sentence[1] this $ echo $sentence[2] ...
16
votes
4answers
730 views

Why some shells `read` builtin fail to read the whole line from file in `/proc`?

In some Bourne-like shells, the read builtin can not read the whole line from file in /proc (the command below should be run in zsh, replace $=shell with $shell with other shells): $ for shell in ...
2
votes
3answers
39 views

Bash read with delimiter past newlines

I have a csv for which I have to extract a specific field. The csv is pipe-delimited (|), with double quotes (") to protect text fields and (this is the catch) newlines in some of the text. eg. ...
1
vote
1answer
38 views

How to read from another terminal?

I opened two terminals (/dev/pts/1 and /dev/pts/2) and started my application from /dev/pts/1. I want to read in real time from /dev/pts/2 but my code doesn't work: actually some of the symbols are ...
0
votes
0answers
50 views

Arch Linux: blk_update_request: I/O error, dev sr0, sector 1452024: unrelated to user input

I just left my Arch Linux installation running in a virtual machine. When I came back to it, I found the following error: [14554.169929] blk_update_request: I/O error, dev sr0, sector 1452024 ...
0
votes
2answers
40 views

Run a command which returns a string when reading a file [duplicate]

I have this idea and maybe it is not feasible, but I think it worth asking. Let's say a user is running this command: cat ~/file.txt Whenever something tries to read from this file, I would like ...
0
votes
2answers
97 views

Why does `read` not pick up all my vars?

My apologies for the very basic question, but can someone please help explain why the following does not print 3 2 1 6 5 4? echo '1 2 3 4 5 6' | while read a b c; do echo result: $c b a; done ...
3
votes
1answer
67 views

Bash script - auto complete for user input based on array data

In a bash script I'm reading some user input with read. Now I want to provide the possibility to auto-complete the input by hitting the Tab key. Easy example: Let's say, the user shall type in a name ...
2
votes
2answers
67 views

bash read of a newline, printf reports character 0

I use bash printf function to print ASCII codes of characters in an input file, but for some reason printf outputs ascii code 0 for LF characters, instead of 10. Any ideas why? while IFS= read -r -n1 ...
1
vote
1answer
43 views

Creating a virtual file whose contents are determined programmatically [duplicate]

Is it possible to create a virtual file in unix, whose contents are determined programmatically when the file is accessed, a bit like the files in /proc? For example, I have a program that retrieves ...
3
votes
1answer
52 views

Iterating over multiple-line string stored in variable

I read that it is bad to write things like for line in $(command), the correct way seem to be instead: command | while IFS= read -r line; do echo $line; done This works great. But what if what I ...
1
vote
2answers
80 views

Why is this script looping on the first line of the txt file?

#!/bin/bash usernameFile="/home/netadmin/username_list.txt" logFile="/var/log/netvpn-mag-archive/netvpn-mag-20160" while read -r line < $usernameFile; do if [[ "$line" != " " ]]; then ...
0
votes
0answers
36 views

Random write on DISK benchmark shows high read rate on iostat

I am running a random write benchmark directly on some disks (HDD & SDD) and I am getting some weird output data on the iostat monitor. Besides the usual write rate, there is a read rate that I ...
1
vote
4answers
56 views

Why does read with pipeline fail in an ssh session?

Why does this show blank lines instead of folders found by find? ssh -o stricthostkeychecking=no -o userknownhostsfile=/dev/null \ -o batchmode=yes -o passwordauthentication=no user@myserver.xx \ ...
-3
votes
2answers
28 views

What does the -p option do in the read command?

What does the -p option do in the read command? An example: read -p "Please enter your first name: " firstName An explanation of the -p option on read's manual page (I don't understand this): ...
6
votes
1answer
240 views

Setting a IFS for a bash script

The typical case is IFS= read. The subject is very well explained in this thread: why is setting a variable before a command legal in bash? In order to have a complete picture, I'd be very grateful if ...
0
votes
2answers
42 views

Read line is ignored

I have problem with a simple read. I read a list of items xml items and then I work with them. In some point I need to ask if Im sure and accept this response in a variable. My problem is that if I ...
2
votes
2answers
61 views

Read a password securely from within process substitution?

Related: Securely feeding a program with a password How to read from stdin in process substitution? Process substitution and cat: can't read stdin I've read the above questions and I still ...
1
vote
0answers
29 views

Bash one liner not looping [duplicate]

I am trying to loop through a file to run commands remotely via SSH but its only sending the first command and stopping. while read a b c; do ssh root@$remoteserverip "/usr/bin/mysql -e \"grant all ...
1
vote
1answer
102 views

Implement a shell in a bash script [closed]

I am trying to emulate a shell in a bash script, like this: cmd_shell() { while true; do read -e -p 'pass> ' command run_cmd $command done } It works ok, and the option ...
3
votes
2answers
236 views

How does the -d option to bash read work?

I have a bash script where I'm trying to assign a heredoc string to a variable using read, and it only works if I use read with the -d '' option, i.e. read -d '' <variable> script block ...
1
vote
3answers
543 views

Read a file line by line and if condition is met continue reading till next condition

I have a file foo.txt test qwe asd xca asdfarrf sxcad asdfa sdca dac dacqa ea sdcv asgfa sdcv ewq qwe a df fa vas fg fasdf eqw qwe aefawasd adfae asdfwe asdf era fbn tsgnjd nuydid hyhnydf gby asfga ...
1
vote
1answer
36 views

Pause (with read or similar) in xargs

I have a script that looks something like the following. find /path -type f | sed -re 'stuff' | xargs -Ix sh -c '{ echo "information about x" ./exe < x read }' My goal is to provide each ...
1
vote
1answer
45 views

Extract fields of a line into shell variables

I have a few hundred lines like below in connRefused.log:- 2015-12-12 00:12:10,227 ERROR [Testing-KeepAlive-01] c.v.v.v.Connection [Connection.java : 001] failed to bind to ...
1
vote
1answer
25 views

Keep \ in read variable to show space [duplicate]

Trying to keep spaces in the variable for read with the \. $ echo "Drag folder to be copied to terminal and press ENTER." $ read FILE /Users/UserName/Desktop/Folder\ With\ Spaces\ In\ it $ echo ...
1
vote
1answer
54 views

Linux bash script input without using “read” [closed]

I need to create a bash script where a single argument is passed by the user (without using the "read" input option) at the terminal command line that creates a directory with that name, or otherwise ...
0
votes
1answer
33 views

How to backup /user/home with some requirements?

I'm currently studying scripting and I need to create an script to back up the /user/home using .bz2 compression. My teacher wants the person running the script to select the user to backup and the ...
-1
votes
1answer
46 views

Read words with spaces as one word

I'm attempting to read words with spaces as one words and multiple spaces as a second word. Is there an easy way to do this: UNLIMITED TABLESPACE TRUSH SELECT ANY DICTIONARY ...
3
votes
3answers
558 views

Reading stdin into a bash array

I want to accomplish the equivalent of: list=() while read i; do list+=("$i") done <<<"$input" with IFS=$'\n' read -r -a list <<<"$input" What am I doing wrong? ...
2
votes
2answers
613 views

How to make bash built-in “read” ignore commented or empty lines?

(For simplicity I'll assume the file to read is the first argument - $1.) I can do what I want externally with: tempfile=$(mktemp) awk '/^#/ {next}; NF == 0 {next}; {print}' "$1" > $tempfile ...
1
vote
3answers
95 views

Printing a line at a specified offset in a file

I have a file with 50 characters on each line and 50 lines. Each line of the file contains arbitrary letters. I want to specify a character sequence number (ex: 52) and have the appropriate line of ...
1
vote
2answers
40 views

Saving data between names in terminal to new files?

I have the following text file: (Employee Ashley) insert text here (Employee Bob) insert text here (Employee Joseph) insert text here I would like to take the text for each "employee" and ...
3
votes
1answer
812 views

How to use user input as a while loop condition

I can do this in bash: while read -n1 -r -p "choose [y]es|[n]o" do if [[ $REPLY == q ]]; then break; else #whatever fi done which works but seems a bit redundant, ...
3
votes
1answer
7k views

How to get total Read and write IOPS in linux

How do i get Read and write IOPS separately in Linux? using command line or in a programmatic way. i am installed sysstat package. Please tel me how do i calculate separately using sysstat package ...
-1
votes
2answers
342 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 ...
1
vote
1answer
175 views

Deadlock on read/wait [closed]

My process deadlocks. master looks like this: p=Popen(cmd, stdin=PIPE, stdout=PIPE) for ....: # a few million p.stdin.write(...) p.stdin.close() out = p.stdout.read() p.stdout.close() exitcode = ...
1
vote
2answers
390 views

How to while read line with a pipe

I am currently trying read a csv file with BASH. The 10th [$f10] value of the csv file must be greater then 0 for a given machine class and machine ID [m_class] and [m_id] (these are user defined) . ...
3
votes
3answers
105 views

Wait for key in shell script that may get piped to /bin/bash

Consider the following shell script echo foo; read; echo bar Running bash my_script outputs 'foo', waits for the return key and outputs 'bar'. While this works fine running it that way, it doesn't ...
1
vote
1answer
117 views

Reading input fields separated by spaces

How can I read in POSIX bash input like this: <name>,<tag1> <tag2> <tag3>… I tried while read line;do done but this wants newlines, all I have is spaces. (Is IFS solution? ...
0
votes
1answer
71 views

Cannot get interface information using read

The following link has a script to get system information: z3bra' blog Specifically, network() { read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'` if iwconfig ...
1
vote
1answer
199 views

Shell read script for sftp

I have this working: % cat read.sh !/bin/sh file=list.txt while read line do echo "$line" cut -d' ' -f27 | sed -n '$p' > file2 done < "$file" % cat list.txt sftp> #!/bin/sh sftp> ...
-1
votes
1answer
134 views

How to Interactively ask a user to change Permissions for a Specified File

I need to create a script that will allow a specified file to have its permissions changed interactively by asking the user if they would like to enable Read, Write and/or Execute one by one for each ...
0
votes
3answers
254 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?
1
vote
0answers
59 views

Responding to prompts automatically?

Lets say I have a script called RPS that simulates rock paper scissors. For example lets say I run the script with "$sh RPS". The script will echo "paper" and then prompt me for an input. Obviously ...
0
votes
0answers
81 views

reading dates from process substitution using awk. Issue with field separator, splitting tokens incorrectly

I have the following code, thanks to @Janis for the help with the process substitution. Also, apologies for creating a new question, I haven't received any recent replies on the thread of my previous ...
2
votes
2answers
47 views

Triggering zero-byte reads on FIFO/pty

I'd like to know how to emulate the ICANON behavior of ^D: namely, trigger an immediate, even zero-byte, read in the program on the other end of a FIFO or PTY or socket or somesuch. In particular, I ...
1
vote
1answer
2k views

What is the meaning of read -r ?

in order to understand another answer: find / -type d -print0 | while read -r -d ''; do ls -ltr "$dir" | sed '$!d' the first step is to understand the usage of the option -r of the read command. ...
1
vote
1answer
586 views

BASH function to read user input OR interrupt on timeout

I am trying to write a BASH function that will do x if program a or b finish. example: echomessage() { echo "here's your message" if [[sleep 3 || read -p "$*"]] then clear fi } In this ...
0
votes
3answers
2k views

Read lines and match against pattern

I can't figure this out. I need to look at every line in file and check out whether it is matching word which is given in variable I started through command read, but I don't know what am I supposed ...
1
vote
1answer
199 views

Shell : while read line nested

I've two documents: doc1.lst and doc 2.lst I want to take the content of each line and put it as parameters for my SQL query. I tried something like this, please correct me file=doc1.lst ...