LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-02-2008, 06:04 AM   #1
dizowned
LQ Newbie
 
Registered: Jan 2008
Posts: 19

Rep: Reputation: 0
stdin redirection


Hey, I was wondering would anyone know why redirecting from standard in doesnt work with all basic commands? For instance if I create a text file named input with names in it say: bob and phil. Then all i want to do is execute something like "mkdir < input" or "rm < input". Either one of these commands will return to the command prompt with no work done, no error outputted or anything. Is there something about creation and deletion commands no being able to have there input redirected? I've tried this from C-Shell and Bash (I don't think the shell makes a difference, but I figured it was worth a shot).

Any replies are much appreciated, thanks.
 
Old 04-02-2008, 06:29 AM   #2
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
try xargs.

$ cat input | xargs rmdir

I don't have a linux handy, but I've done that on Solaris and I just tried it on OpenBSD.
 
Old 04-02-2008, 07:22 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Well, if you were to type mkdir or rm without arguments would it give you the option to type something in? If not, then there's no reason for it to work with <. Many programs default to standard input for parameters when none are provided, such as cat, but for some it doesn't make sense so they don't do it. Those programs don't even attempt to read from standard input. The redirection works, but the program doesn't implement it.
ta0kira

PS You could use mkdir `cat input`.

Last edited by ta0kira; 04-02-2008 at 07:25 AM.
 
Old 04-02-2008, 07:39 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
i agree.

rm doesn't accept stdin, there you go.

use xargs as suggested.
 
Old 04-04-2008, 01:45 AM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
you can also do
Code:
mkdir $(<input)
and to make it work with filenames that has spaces and are separated by newlines:
Code:
IFS=$'\n'
mkdir $(<input)
IFS=$' \t\n'
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] reading from stdin lord_didger Programming 5 01-16-2008 09:27 AM
Using stdin in a select nc3b Programming 2 06-11-2007 08:19 AM
Logging via stdin bubblenut Linux - Server 4 02-12-2007 12:00 PM
redirection data to stdin Majestros Programming 2 07-07-2004 09:20 AM
unbuffered stdin mvt Programming 7 05-17-2004 09:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration