LinuxQuestions.org
Review your favorite Linux distribution.
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
 
LinkBack Search this Thread
Old 04-21-2007, 03:59 AM   #1
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Rep: Reputation: 16
reading variable while remaining on the same line - bash


Here's a function that allows create simple user accounts in a htpasswd file.
Code:
					printf "\nThe team has the following members:\n"
					cat $VAR_TEAM_ROOT/auth | cut -d: -f1
		            printf "\nEnter member with password to add:\n"
                	# until get an empty member name or password
                	MEMBER=1
                	PASSWORD=1
                	until [ -z "$MEMBER" ] || [ -z "$PASSWORD" ]
                	do
                        read MEMBER PASSWORD
                        	LISTING_TEST "$VAR_TEAM_ROOT/auth" "$MEMBER"
                       		if [ "$?" = 1 ]
                       			then
                       				printf "[\e[1;32m+\e[m]\n"
                       				# add to auth file
                        			htpasswd -b $VAR_TEAM_ROOT/auth $MEMBER $PASSWORD &> /dev/null
                        			# set trac permissions
									trac-admin $VAR_TEAM_ROOT/trac permission remove "$MEMBER" &> /dev/null
                        			trac-admin $VAR_TEAM_ROOT/trac permission add "$MEMBER" developer &> /dev/null
                        		else
                        			printf "[\e[1;31m-\e[m]\n"
                        	fi
                	done
LISTING_TEST verifies the value entered against the list of users already in the file and returns "1" in case user is not found (what we basically need). In this case user gets added to the file and a "[+]" sign is printed on the next line.
The question is: how can I make the sign appear on the same line name and pass are displayed?
So that it would look like
user password [+]

Just out of ideas . Thanks.
 
Old 04-21-2007, 05:28 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

This can probably be done with tput

Code:
#!/bin/bash

read MEMBER PASSWORD

tput cuu1
tput cuf 35
printf "[\e[1;32m+\e[m]\n"
You will probably need to do some arithmetic to calculate the exact col position (cuf 35 in my example). Or you could decide to give it a fixed width (as in my example).

Here are 3 related URL's
Linux / Unix Command: tput
Colours and Cursor Movement With tput
(example) The Floating Clock Prompt

Hope this helps.
 
Old 04-21-2007, 05:52 AM   #3
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Original Poster
Rep: Reputation: 16
Awesome!
Though it looks a bit cryptic, works like charm. I'll study more on tput, thanks for the reference.
 
Old 04-24-2011, 09:47 AM   #4
kitoper
LQ Newbie
 
Registered: Apr 2011
Posts: 1

Rep: Reputation: 0
rudimentary read tag

Read -p "insert text here" variable_here
 
  


Reply

Tags
bash


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
Bash store last line from displayed text output in a variable carl0ski Programming 1 01-16-2007 03:38 AM
[Bash] New line character in variable michael_hk Linux - Newbie 4 06-15-2006 02:13 PM
File reading line by line and compare Goni Linux - Software 14 09-21-2005 12:24 AM
bash: reading a particular line seb3579 Linux - Newbie 2 09-14-2004 03:01 AM


All times are GMT -5. The time now is 04:56 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration