[완료]shell 프로그램을 만들고 있는데 입력에서 질문입니다.

anaud2의 이미지

안녕하세요

리눅스 환경에서 새로운 shell프로그램을 만들고 있는데요
패스워드를 입력을 받을때 화면에 안보이게 하는부분은

struct termios init_term;
struct termios new_term;
char buffer[10]="\0";
tcgetattr(fileno(stdin), &init_term);
 
new_term = init_term;
new_term.c_lflag &= ~ECHO;
 
tcsetattr(fileno(stdin), TCSAFLUSH, &new_term);
scanf("%s",buffer);
tcsetattr(fileno(stdin), TCSANOW, &init_term);

위와 같이 했습니다. 그런데 입력을 하던중 백스페이스를 누르게되면 앞에 입력한 부분이 지워진다고 생각을 했었는데
shell프로그램에 적용을 시켜보니까 지워지지않고 ^H라는 부분이 그대로 삽입이 되더라구요

이전에 질문을 드렸었때에는 고마우신분께서 stty -a 에서 쉘에 설정이 다르게 되어서 그럴지 모른다 라고 하셨습니다. /bin/bash을 사용하는데 보면 erase = ^H; 로 되어있어서 백스페이스가 맞는데 왜 문제가 생길까 생각을 했습니다.

그런데 제가 만들려는 쉘말고 다른계정으로 로그인하던중 "login: "여기에 아이디를 입력을 할때 잘못해서 백스페이스를 입력을 하니 화면에 이렇게 나오더군요 "login : anau^H^H"
제가 stty -a 에서 살펴본건 로그인후 사용하는 쉘에 설정인거 같고
로그인 과정에서 사용 하는 쉘(쉘이라고 표현을 하는게 맞는지 모르겠지만 제가 만들려는 부분과 같은 로그인시 아이디와 비밀번호를 입력 받는과정의 환경)에서는 백스페이스가 지우는게 아니라 ^H로 인식이 되게 되어있나봐요 ..이걸 어떻게 바꿔야지만 패스워드를 입력할때 지워지는거 같은데
어떻게 하면 좋을까요? getpass, scanf 등 어떤걸 써도 백스페이스가 안먹히네요 ㅠ

dorado2의 이미지

man termios에서 ICANON, VERASE부분을 확인해보세요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.