Questions tagged [stdin]

49 questions
74
votes
8 answers

How to write a script that accepts input from a file or from stdin?

How can one write a script that accept input from either a filename argument or from stdin? for instance, you could use less this way. one can execute less filename and equivalently cat filename | less. is there an easy "out of the box" way to do…
gilad hoch
  • 843
  • 1
  • 7
  • 8
21
votes
3 answers

Windows how to redirect file parameter to stdout? (Windows equivalent of `/dev/stdout`)

Windows console: Tool A can write binary data to a file, but has no option for telling it to use stdout. Tool B can read binary data from stdin and process the info in it. How can I get the output from A piped through B without using an…
Jeroen Wiert Pluimers
  • 2,853
  • 10
  • 41
  • 55
19
votes
6 answers

Clear stdin before reading

I have the following bash script: # do some time consuming task here read -p "Give me some input: " input Now as you might have guessed, if a user presses some random keys during the "time consuming task", the unwanted input is taken into account…
rabin
  • 305
  • 2
  • 3
  • 7
18
votes
4 answers

Who deals with the star * in echo *

Who deals (interprets) the * in echo * Does the echo see the star or the shell take care about it and return a list of filename .. What about cp temp temp*
faressoft
  • 393
  • 2
  • 6
  • 14
14
votes
5 answers

compare two directory trees

I have two music libraries, one a newer version than the other. I would like to compare them to figure which files I need to copy from new music tree to old. I have tried diff --brief -r /oldmusicdir/ /newmusicdir/ based on another user's…
curios
  • 350
  • 1
  • 3
  • 13
14
votes
2 answers

Indicating end of Standard Input

How does one indicate that one has finished entering test in stdin? For example, let's say that I wish to encrypt 'blue' using MD5 (I know MD5 is unsecure, but just for this example). I tried user$ blue | md5 which I was led to understand is how…
waiwai933
  • 2,483
  • 7
  • 28
  • 44
13
votes
3 answers

Two Programs having their StdIn and StdOut tied

Suppose I have two programs called ProgramA and ProgramB. I want to run them both simultaneously in the Windows cmd interpreter. But I want the StdOut of ProgramA hooked to the StdIn of ProgramB and the StdOut of ProgramB hooked to the StdIn of…
DarthRubik
  • 283
  • 2
  • 11
11
votes
1 answer

Read from stdin to new, named, file in vim

I'd like to start vim on a non existing file, named f, with the content c. Both f and c are arbitrary and I'd like to not have to put anything in the vim config to fill new buffers with c. Basically, I would like to combine $ echo c | vim - with $…
chelmertz
  • 341
  • 1
  • 2
  • 12
8
votes
1 answer

Getting back to "stdin" after redirecting a file to a particular program

I need to achieve a particular effect using bash's redirection facilities. I know that I can redirect a file to some program's standard input: [user@host]$ application < file.txt The thing is, I'd like to know can I regain control of this program's…
Neo
  • 2,047
  • 4
  • 18
  • 20
7
votes
3 answers

Feeding multiline input (here documents) to commands in cmd.exe scripts

In Bash, I can do something like this somecmd << END a lot of text here END to feed input to a command directly from a script. I need to do the same in CMD.exe batch files (.cmd scripts). Is it possible?
Krumelur
  • 667
  • 4
  • 11
  • 19
5
votes
3 answers

zip extractor reading archives from stdin

As follows from UNZIP(1L) man page Archives read from standard input are not yet supported Are there another CLI programs running under Linux/cygwin which can extract from zip archives reading them from stdin?
vect
  • 225
  • 3
  • 9
5
votes
1 answer

Cat hangs when attempting to read empty STDIN

My script attempts to gather information that may or may not be present in STDIN at execution time, but cat hangs if the pipe is empty. How can I ensure that my script skips this step if this there is nothing in STDIN? stdin=$(cat <&0) Note that I…
StarCrashr
  • 153
  • 1
  • 5
4
votes
1 answer

shell standard streams redirection order OR 2>&1 1>/dev/null vs 1>/dev/null 2>&1

Can somebody please clarify differences? Is some of those considered as best practice? If I remember correct I somehow on SO read that this 1>/dev/null should precede this: 2>&1 ls -al /doesNotExists 2>&1 1>/dev/null ls -al /doesNotExists…
Wakan Tanka
  • 729
  • 2
  • 13
  • 31
4
votes
1 answer

Run command for every line of a file in bash, passing lines as standard input

How do I pass some input to a command line by line (ie. invoke the command for every line)? xargs does not work because it passes the lines as arguments, not as standard input. The specific case where this came up was decoding a file whose lines…
Tgr
  • 2,953
  • 4
  • 26
  • 31
4
votes
5 answers

Bash/csh: test for end of file (EOF) of stdin

I would like to do: if not eof(stdin): pass stdin to program else: do nothing I have a feeling that it can be written fairly close to: if test ! --is-eof - ; then exec program The problem I am trying to solve is that program reads from…
Ole Tange
  • 4,529
  • 2
  • 34
  • 51
1
2 3 4