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 02-16-2009, 11:56 AM   #1
Carlos2dub
LQ Newbie
 
Registered: Aug 2007
Location: Madrid
Distribution: Debian 4, openSUSE 10.3, RHEL 5
Posts: 24

Rep: Reputation: 15
how to format the output?


Hi all,

Im new to bash scripts, and I was trying to do a password generator script. Everything went fine but, the output I get is always separated by spaces and I need it all together. Any ideas about how to make this?

Code:
#!/bin/bash

X=0

VALUES=(
q w e r t y u i o p a s d f g h j k l z x c v b n m Q W E R T Y U I O P A S D
F G H J K L Z X C V B N M 1 2 3 4 5 6 7 8 9 0 ! @ # $ % ^ & * ( )
)


while [ $X -lt 8 ];do
        PASS[X]=${VALUES[$[($RANDOM % 65)]]}
        X=$(($X + 1))
done

PASSWORD=${PASS[*]}
echo $PASSWORD
Thanks a lot,

Carlos.
 
Old 02-16-2009, 12:04 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Try this:
Code:
#!/bin/bash

X=0

VALUES=(
q w e r t y u i o p a s d f g h j k l z x c v b n m Q W E R T Y U I O P A S D
F G H J K L Z X C V B N M 1 2 3 4 5 6 7 8 9 0 ! @ # $ % ^ & * ( )
)


PASS=""
while [ $X -lt 8 ];do
        PASS=${PASS}${VALUES[$[($RANDOM % 65)]]}
        X=$(($X + 1))
done

PASSWORD=$PASS
echo $PASSWORD
 
Old 02-17-2009, 02:25 AM   #3
Carlos2dub
LQ Newbie
 
Registered: Aug 2007
Location: Madrid
Distribution: Debian 4, openSUSE 10.3, RHEL 5
Posts: 24

Original Poster
Rep: Reputation: 15
Thanks a lot, new I get the idea
 
Old 02-17-2009, 10:09 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Cool!

And please feel free to click the little blue "thumbs up" icon if you think this (or any!) post was of help to you!

Your .. PSM
 
  


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
Format output pslacerda Linux - Newbie 12 12-21-2008 09:01 AM
How can i get the ls command to output in the following format deathalele Programming 3 11-16-2008 02:07 PM
output format ust Linux - Newbie 2 09-11-2008 01:14 AM
Format bash output ceashton Programming 3 08-17-2007 12:16 PM
last command output format bujecas Linux - General 1 10-12-2006 09:54 AM

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

All times are GMT -5. The time now is 05:25 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