LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2012, 12:55 PM   #1
juacala
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Rep: Reputation: Disabled
Accepting text from command line like you would a file


I know you can essentially replace STDIN with a file by doing something like:

<command> < file.txt

Is there a way to do that with actual text? In my mind it would look something like:

<command> < 'some text to use as input in the script'

However, I can see that that might not work since, it's hard to do things like carriage returns. So similarly, if I did want carriage returns, could I do something like "some text\n some more text\n" to emulate the carriage returns.

The reason I'm asking is I want to pass passwords, and I don't like the idea of creating temporary files with the passwords in there.
 
Old 06-08-2012, 12:59 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
1) Use here documents to pass text to stdin

http://mywiki.wooledge.org/BashGuide...nd_Herestrings

2) Modern shells like bash and ksh have an ansi-c style quoting mechanism ($'foo\nbar'), which expands backslash escapes in text strings.
http://mywiki.wooledge.org/Quotes

3) Use expect to script the running of commands in place of an actual user.


But you should never, ever store passwords or other sensitive information directly inside scripts or other freely-readable files.

Last edited by David the H.; 06-08-2012 at 01:06 PM. Reason: added one + edits
 
Old 06-08-2012, 03:34 PM   #3
juacala
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks. That answers my question. I wasn't going to store the password in the script. I was going to accept it as input, and then reuse it a couple of different times within the script.

Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] trying to insert text in the last line of a file with sed command.... Sayan Acharjee Linux - General 7 10-04-2010 05:00 AM
insert text to a file using command line replica88 Linux - Newbie 4 01-28-2010 05:50 PM
How to copy command line commands into a text file... visitnag Linux - Newbie 6 04-26-2009 04:11 AM
Command to print last line of a text file Micro420 Linux - General 3 01-25-2007 01:17 AM
chpasswd from a command line (without a text file) mpgram Linux - Security 1 04-18-2004 05:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:32 PM.

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