Jump to content

Tutorial: Shell Scripting - Username/Password

- - - - -

  • Please log in to reply
4 replies to this topic

#1
veda87

veda87

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
I am gonna teach about a shell script to do something like this

Quote

Username: veda
Password: *****
Here is the code

#! /bin/sh                  # bash interpreter. Tell the OS that it is bash interpreter

echo -n "Username: "        # prompt it on the console; -n means no new line 

read username               # reads the input from the console and assign its to username

echo -n "Password: "

while [ 1 ]                 
do
    read -s -n1 key       # reads the input; -n 1 means read only one character at a time; -s means silent, it means don't display what is read

    echo -n "*"

    if [[ $key == "" ]];  # checks whether enter is pressed
    then
        exit 0         # exit with return value 0
    fi
exit 0
I guess the code is self explanatory...

Now,How to run this code...

Once the program is ready,
Now change the permission of the program it command is
chmod u+x filename

Quote

chmod - change mode
u - user
x- executable
u+x - add executable permission to the user
filename - name of the file
and now run as
./filename

Quote

. means current directory
./filename means execute the file in current directory
Hope you would have learnt something....

#2
dazuko

dazuko

    Newbie

  • Members
  • Pip
  • 1 posts
Thanks for the tutorial...

#3
Gigia

Gigia

    Newbie

  • Members
  • Pip
  • 9 posts
Will be better if you mention in heading of thread about which shell are you talking about. For example now you talking about bash.

#4
h1t4k3

h1t4k3

    Newbie

  • Members
  • Pip
  • 3 posts
nice tutorial :D
but what the function of this script ?

#5
h1t4k3

h1t4k3

    Newbie

  • Members
  • Pip
  • 3 posts
nice tutorial :thumbup:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users