The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
1answer
32 views

read reading input devided 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
50 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
62 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
53 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
63 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
30 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
48 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
33 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
111 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. ...
0
votes
1answer
121 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
183 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
79 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
193 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
628 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
225 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
468 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
736 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
142 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
45 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
781 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
113 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
123 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" ...
4
votes
2answers
295 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 ...
5
votes
3answers
530 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
196 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
133 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
679 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 ...
1
vote
2answers
68 views

Using sed with herestring (<<<) and read -a

I use sed with <<< and read to assign all words in a string to variables. What I do is: read -a A0 <<< $(sed '2q;d' /proc/stat) Hence, sed reads the second line of the file file ...
2
votes
1answer
222 views

read specific lines from the file [duplicate]

I have some text file (for example json). I can use head order for the reading of the first lines. For example: head -n 100 file.json get me 100 first lines back. What is Linux order, which I can ...
1
vote
3answers
720 views

How to handle backspace while reading?

How do I handle the backspaces entered, it shows ^? if tried & how read counts the characters, as in 12^?3 already 5 characters were complete(though all of them were not actual input), but after ...
6
votes
3answers
158 views

Succinct way to respond to user input?

Of course you can do this sort of thing, read var; if [[ $var = 'y' ]]; then echo "Yes"; fi But is there any way to skip the first step and do something a little more like this, (ideally without ...
4
votes
2answers
138 views

Print currently pressed keys to stdout and read them line by line

I want to know which keys are pressed on my keyboard and print the information to stdout. A tool that can do this is showkey. However, if I want to pass the data of showkey to read: while read line; ...
3
votes
1answer
839 views

Why does the read command not take interactive options when run by sh?

I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the ...
1
vote
0answers
25 views

How to combine Bash's read with HERE-document when shopt -os errexit is in place? [duplicate]

I am trying to make use of the solution presented in one of the answers of http://stackoverflow.com/questions/1167746/how-to-assign-a-heredoc-value-to-a-variable-in-bash In Bash version ...
2
votes
3answers
202 views

In what shared library is read()?

I'm a Linux rookie and want to know where the system call read() is. Which shared library is linked when I call read()?
2
votes
2answers
3k views

Read non-bash variables from a file into bash script

My bash script needs to read the variables from a text file that contains hundreds of variables, most of which conform to standard bash variable syntax (e.g., VAR1=VALUE1). However, a few lines in ...
1
vote
2answers
236 views

Run a Shell script and read the output in a variable and run another script based on output

I am a novice to Linux system. My requirement is to run a Linux status script which echos a message (message is either "App is running" or "App is not running"). If the message is "App is running" ...
7
votes
3answers
3k views

Bash: interactive remote prompt

I have a script which connects to a remote server and check if some package is installed: ssh root@server 'bash -s' < myscript.sh myscript.sh: OUT=`rpm -qa | grep ntpdate` if [ "$OUT" != "" ] ; ...
2
votes
5answers
247 views

Read contents in a line in bash

I have a file with contents in this order which is separated by space 4096 1230 4560 1024.... n How can i read each number and pass it on to another command, eg divide each number by 1024.
1
vote
1answer
358 views

Read a variable with “read” and preserve backslashes entered by the user

I'm using read to read a path from a user like so: read -p "Input the file name: " FilePath The user now enters this string: \Supernova\projects\ui\nebula What can I do to replace \ with /. The ...
10
votes
3answers
354 views

bash: Some issue when using read <<<“$VARIABLE” on a read-only root partition. Any known workarounds?

Just by coincidence I had to use my ATA-ID-to-device-name script (found here: http://serverfault.com/questions/244944/linux-ata-errors-translating-to-a-device-name/426561#426561) on a read-only / ...
1
vote
1answer
407 views

while loop is running only once?

I am trying to make a clip out of video file by playing it only for certain interval. make_mclip.sh #!/bin/bash mediafile=$@ mediafile_fullpath=$PWD/./$mediafile tmpedlfile=$(mktemp) mplayer ...
2
votes
1answer
86 views

Monitoring file reads for cache warming

After adding more memory to my Linux machine I was tempted to use the cache more agressively. The thing is: I boot up my machine, go to bathroom, come back and log in. It takes like half a minute to ...
0
votes
2answers
8k views

Read the output of a command into a variable [duplicate]

I am making a bash script but I'm totally new and got lost. I've made this code cat * | grep "|*parameter1*|" | grep "|*parameter2*|" | cut -f 8,11,12,15,21,23,34 -d "|" | wc -l which works just ...
5
votes
2answers
496 views

read -a array -d '\n' < foo, exit code 1

If I try to execute read -a fooArr -d '\n' < bar the exit code is 1 -- even though it accomplishes what I want it to; put each line of bar in an element of the array fooArr (using bash 4.2.37). ...
1
vote
2answers
336 views

Nested read fails

I have a list of filenames in a file and want to do let the user decide what to do with each. In bash, iterating over filenames is not trivial in itself, so I followed this answer: #!/bin/bash while ...
4
votes
1answer
1k views

Read space as input in shell script [duplicate]

How can I give space " " as input in shell script ? Ex : echo " Enter date for grep... Ex: Oct 6 [***Double space is important for single date***] (or) Oct 12 " read mdate echo $mdate I get the ...