Wednesday, May 23, 2012

How to assign a password present in a file to a variable ?

Let's say you have a file 'secretfile' which contains the password 'newpass'. You want to assign the password mentioned in that file to a variable called 'pass1'.  The syntax will go like this:

# cat  secretfile

Method 1
# pass1=$(cat secretfile)
# echo $pass1

Method 2
# read pass1 < secretfile
# echo $pass1

No comments:

Post a Comment

Popular Posts

About Me

My photo
I have started this blog to share my work experience and spread some smart solutions on Linux to Internet community. I'm hoping more people will get benefited from this blog. Brief about me: I have 16+ years experience working as System Admin and currently work with VMware.