The tag has no usage guidance.

learn more… | top users | synonyms

3
votes
2answers
46 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
47 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
66 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
132 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
21 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
37 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
20 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
39 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
31 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
30 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
282 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
170 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 ...
25
votes
5answers
2k views

How does Linux differentiate between real and unexisting (eg: device) files?

This is a rather low-level question, and I understand that it might not be the best place to ask. But, it seemed more appropriate than any other SE site, so here goes. I know that on the Linux ...
1
vote
3answers
69 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
339 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, ...
2
votes
1answer
2k 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
197 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
120 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
294 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
85 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
87 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
68 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
168 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
93 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
177 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
53 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
73 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
45 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
1k 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
472 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
2answers
1k 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
170 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 ...
1
vote
2answers
418 views

use “read” command to pass lines as positional parameters to a shell script

The following file runs, but not doing anything, yet it does not error.... while read dates; do ./avg_hrly_all_final.sh ${dates}; done < ./dates_all.csv I have a list of dates in ...
0
votes
0answers
23 views

printf>stdin unusable with read [duplicate]

With read, sending "a" to stdin is not equivalent to pressing "a" (or use your favorite letter/key). Tested this: ~$ read -n1 & fg [1] 11620 read Then "typed" "a" into the read process stdin ...
1
vote
3answers
789 views

Read longest line in file using while read loop?

I've been googling but I can't find any scripts that uses the while loop to read the lines. I'm stuck and I'm not sure on where to start Heres the question: Write a bash script longestline.sh that ...
2
votes
3answers
1k views

Reading multiple files one line at a time in bash

I know the basic way of reading from a command in bash: cal | while IFS= read -r line ; do echo X${line}X done But what if I want to read one line from several files/commands in a loop? I've ...
1
vote
2answers
2k views

Read line from file then delete

How can I read a series of lines from a file and then remove each line? Obviously I can read like this: while read -r line; do echo $line done < myfile.txt But if I do this: while read -r ...
4
votes
3answers
2k views

Piping a script with “read” to bash

I need to run a script by piping it through bash with wget(rather than running it directly with bash). $ wget -O - http://example.com/my-script.sh | bash It's not working because my script has read ...
1
vote
1answer
373 views

Read from character delimted file and assign into variables | for email

I am using ksh. I need to read the data from file, into the variables and then further use them for sending emails. File can be delimited by any less used characters (like | ^ etc.) or group of ...
2
votes
1answer
55 views

Input separator of the `read` builtin in Bash

Given such situation: echo "Please enter your name" read name # user enters: john smith echo $name # prints: john What could cause read to read only the first word of the input? Is there a ...
3
votes
1answer
2k views

bash: non blocking read inside a loop

I have a following small bash script var=a while true : do echo $var sleep 0.5 read -n 1 -s var done It just prints the character entered by the user and waits for the next input. ...
3
votes
1answer
121 views

Reading char-by-char silently does not work

I'm trying to read user input char by char, silently, as follows: while [ 1 ]; do read -s -N 1 ... done While this loop works perfectly using VNC (xterm), it works only partially using putty ...
3
votes
1answer
224 views

Problem with getting interactive input in while read loop

I was doing something like the following minimal example: #! /bin/sh # $1 = file containing list of files to sync # $2 = source dir ; $3 = target dir cat "$1" | while read f do cp -i "$2"/"$f" ...
6
votes
2answers
613 views

How to read user input when using script in pipe

General problem I want to write a script that interacts with the user even though it is in the middle of a chain of pipes. Concrete example Concretely, it takes a file or stdin, displays lines ...
6
votes
3answers
1k views

Use bash's read builtin without a while loop

I'm used to bash's builtin read function in while loops, e.g.: echo "0 1 1 1 1 2 2 3" |\ while read A B; do echo $A + $B | bc; done I've been working on some make project, and ...
0
votes
2answers
525 views

Bash Script using read needs to stop executing on Ctrl+D

I need to write a script that will add a line to a text file if Enter is pressed. But, if Ctrl+D is pressed, I need to exit that loop in the bash. touch texttest.txt LINE="0" while true; do read ...
1
vote
1answer
217 views

Custom tab-completion in bash's `read`

Is there a way to "import" a list of words into bash's read builtin to have custom tab-completion? I've been writing a wrapper script for suckless' minimalist irc client "ii", and I don't have a way ...
5
votes
4answers
1k views

Is there a difference between read, head -1, and sed 1q?

The following commands seem to be roughly equivalent: read varname varname=$(head -1) varname=$(sed 1q) One difference is that read is a shell builtin while head and sed aren't. Besides that, is ...