Converting the input characters into ' * '

Converting the input characters into ' * '

Post by Sachin Sharm » Tue, 17 Apr 2001 22:18:26



hello everybody,

I am doing a simple shell script exercise in which i expect the user to
enter a
string ,but instead of the actual characters i want some other character to
be echoed.
i.e If the user enters ABCD, '****' should be echoed in place of ABCD and
this should happen before the user presses the enter key.

I know, it looks like a password reading application but this is only a
learning
exercise.

with regards
sachin

 
 
 

Converting the input characters into ' * '

Post by Michael Heimin » Wed, 18 Apr 2001 00:03:07



> hello everybody,

> I am doing a simple shell script exercise in which i expect the user to
> enter a
> string ,but instead of the actual characters i want some other character to
> be echoed.
> i.e If the user enters ABCD, '****' should be echoed in place of ABCD and
> this should happen before the user presses the enter key.

> I know, it looks like a password reading application but this is only a
> learning
> exercise.

You don't write which shell you want to use, you should always contain
that in
your posts, in order to make it possible for others to help you.

This is working with bash:

read -n 5  -s string ; echo "*****"

Should be something to start, check

man 1 bashbuiltins

Good luck

Michael Heiming
This should although answer your other post.

 
 
 

Converting the input characters into ' * '

Post by Anthony Borl » Wed, 18 Apr 2001 06:35:56



Quote:> hello everybody,

> I am doing a simple shell script exercise in which i expect the user to
> enter a
> string ,but instead of the actual characters i want some other character
to
> be echoed.
> i.e If the user enters ABCD, '****' should be echoed in place of ABCD and
> this should happen before the user presses the enter key.

> I know, it looks like a password reading application but this is only a
> learning
> exercise.

> with regards

Sachin,

It is not the sort of exercise that can be performed, at least easily, in a
shell script. I'd be inclined to write a small C program, using the Curses
library, to accomplish this task. A very-minimal 'Curses-based' program
example appears below; for your purposes you don't appear to need anything
too elaborate.

#include <stdio.h>
#include <curses.h>

/* Driver */
int main()
{
  /* Initialise window */
  initscr();

  /* Print string */
  addstr("Hello, world!");

  /* Pause */
  getch();

  /* Close window */
  endwin();

  return 0;

Quote:}

Having said that, the later versions of shells such as 'bash', offer
enhancements to the 'read' built-in which may facilitate such tasks. The
other respondent to your post provided just such an example.

If you have an older shell, however, the 'Curses' approach is, I believe,
the most viable.

I hope this helps.

 
 
 

Converting the input characters into ' * '

Post by Dan Merc » Wed, 18 Apr 2001 23:18:00






>> hello everybody,

>> I am doing a simple shell script exercise in which i expect the user to
>> enter a
>> string ,but instead of the actual characters i want some other character
> to
>> be echoed.
>> i.e If the user enters ABCD, '****' should be echoed in place of ABCD and
>> this should happen before the user presses the enter key.

>> I know, it looks like a password reading application but this is only a
>> learning
>> exercise.

>> with regards

> Sachin,

> It is not the sort of exercise that can be performed, at least easily, in a
> shell script.

Sure it's easy.  In bash (2.x) it's builtin:

   string=
   i=5
   while ((i--))
      do
      read -n 1 -s c || break
      s="${s}${c}"
      echo -n "*"
      done

Of course, You'll want to add in processing for backspace and carriage
return.

In other Bournish shells,  you need to use stty and dd:

In SysV Bourne sh:

      #!/usr/old/bin/sh

      savetty() {
      SAVETTY=`stty -g </dev/tty`
      }

      rawtty() {
      stty raw -echo </dev/tty
      }

      cookedtty() {
      stty ${SAVETTY:-cooked} </dev/tty
      }

      cr=`echo "\r\c"`
      bs=`echo "\b\c"`
      nl=`echo`
      savetty
      rawtty
      s=
      while true
          do
          c=`dd if=/dev/tty count=1 bs=1 2>/dev/null`
          case $c in
             $cr) break;;
             $nl) break;;
             $bs) [ -n "$s" ] && {
                  echo "\b \b\c"
                  s=`expr "$s" : '^\(.*\).$'`
                  }
                  ;;
              '') break;;
               *) s="${s}${c}";echo "*\c";;
          esac
          done
      cookedtty
      echo "\ns=$s"

It's a lot easier in ksh88,  easier still in ksh93.  But bash
is definitely easiest of all.

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

1. convert 'a' lib' into 'so' lib

I am using a program that uses the glut program.  It seems that the only
version that runs on Solaris is the one for Solaris 7.  After compiling
it, it produces a 'libglut.a' file.  I am need of the 'libglut.so' file
because I use Solaris 8.

Does anyone know how to convert the 'a' lib into a 'so' lib?

Thanks in advance. . .

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Donnie Payne
Systems Administrator
Purdue University, Genomics Facility
1057 Whistler Hall, Room 207
West Lafayette,  IN   47907-1057


 Phone: 765-496-2134
 Fax: 765-496-7255
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2. RedHat GLINT using ftp

3. converting 'struct stat' to 'struct __old_kernel_stat'?

4. need help on DNS setup

5. Convert 'a' to 'A' in a Shell-Script

6. Getting Floppy Drive up. Can not mount normal or -t msdos! Help?

7. Using 'cat' with 'tee' - Input error?

8. *** source browser and debuger ***

9. Swapping 'Ctrl' and 'Compose Character'

10. can sed pattern contain '<' & '>' characters or not?

11. '???' replaces every '-' character in man pages

12. Eliminating 'weird' characters from fax id's

13. converting 'csh' to korn.