LinuxQuestions.org
Visit Jeremy's Blog.
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 09-14-2009, 03:55 PM   #1
dsollen
Member
 
Registered: Jun 2009
Posts: 56

Rep: Reputation: 15
quick question on order of operation with command substitution


Okay quick question, not a major issue but something I ran into a question Iíd like to get answered. I'm creating a script that will be creating a user and setting his password to a default value, but it doesnít behave as I want it to.

I can do what i want if I get the password from a file using the command:
passwd user --stdin < passwordFile

but it dosn't work when I try to get fancy and remove the file
passwd user --stdin <(echo password)
I get the error message "passwd: Only one user name may be specified"


so it seems like in the first command the pipe feeds into stdin after the passwd command is run (causing it to be read as a password), while the second command the pipe happens before the passwd command executed so that it is read as another argument to passwd. I'm assuming the parentheses caused the echo password command to be executed (and thus piped) before the passwd command.

I tried playing with my parenthesis a bit to get passwd command to execute first and couldn't, and ended up settling for what seems a sloppy solution
passwd user --stdin < <(echo password)
which acts as desired.

so Iím wondering, 1) am I correct about why I wasn't getting what I wanted and 2) was there a better way to specify order of operation so I can have the echo command execute after the passwd command without my cheap sloppy trick?


..and before everyone yells at me, the user account Iím making is going to act a bit like a guest account, minimal privileges that anyone can use. I donít think hard coding the password is a security risk even if others could see my script.
 
Old 09-14-2009, 04:10 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Not possible, see Greg's Bash FAQ item on this very topic.
 
Old 09-14-2009, 07:39 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Code:
echo $password | passwd --stdin $user
 
Old 09-15-2009, 09:04 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by chrism01 View Post
Code:
echo $password | passwd --stdin $user
"Not possible" just became possible! But not on ubuntu 8.04 or Slackware 13 where passwd doesn't have the --stdin option.
 
  


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
need quick regex help with substitution BrianK Programming 3 11-14-2007 02:58 PM
quick question on emailing from the command line boyd98 Linux - General 2 04-29-2007 10:38 PM
Bash Command Substitution dakensta Programming 5 11-30-2006 04:10 PM
quick question about the who command AmphetaminePhreak Linux - Newbie 7 08-01-2006 06:07 AM
command substitution: ^ rhxk Linux - General 2 04-06-2006 10:51 AM


All times are GMT -5. The time now is 04:29 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration