1

I have a bash script on CentOS 7.4 with the following line that lets a user input a variable and then lets them confirm that what they entered is indeed correct:

read -p "Enter the name of the database: " dbname
echo "You entered: $dbname"
read -p "Is that correct? Enter y or n: " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1

When I SSH into the CentOS machine from Windows 10 with the Command Prompt app to run the script, sometimes I mistype a letter when inputting the variable and I need to backspace. However, when I try to backspace, the Command Prompt app just types out ^H.

How can I either modify my script or modify a setting somewhere in CentOS or Windows so that my backspace in this setup will actually be functional?

8
  • are you sure that you have the right prefix (#!/bin/bash) at the top of your script ? or how do you run it ? because the behavior you are talking about looks like you are running the script with another shell such as sh or ksh.
    – olivierg
    Aug 6, 2018 at 19:19
  • (you can also try to change the default shell of your centOS user to /bin/bash instead of its default one (probably ksh ?), but assuming that you run the script using the correct command & header, that shouldn't have an impact
    – olivierg
    Aug 6, 2018 at 19:20
  • @olivierg Yup, it has #!/bin/bash at the top. I just SSH into it with Windows Command Prompt. AFAIK, there's no other shell installed on the CentOS box. Is it possible that Windows Command Prompt somehow needs to be set up, specified for bash itself?
    – user260467
    Aug 6, 2018 at 19:22
  • @olivierg ksh is the default for CentOS, not bash?
    – user260467
    Aug 6, 2018 at 19:23
  • @olivierg I just checked from here unix.stackexchange.com/a/76440/144794 and my default is indeed already /bin/bash. I also specify it in the script, anyway.
    – user260467
    Aug 6, 2018 at 19:25

2 Answers 2

0

What are use using on Windows? A common client is Putty. You can define character mappings in Putty.

You can change the setting in Linux. Try

stty erase ^H
3
  • I'm using Windows Command Prompt, as I mentioned in the question.
    – user260467
    Aug 6, 2018 at 19:29
  • The Windows Command Prompt is not a ssh client.
    – RalfFriedl
    Aug 6, 2018 at 19:31
  • I just log in with the ssh command. ssh user@address, and then I enter the password. I guess it's whatever's built into Windows Command Prompt.
    – user260467
    Aug 6, 2018 at 19:32
0

Turns out that Windows Command Prompt is just a bit wacky. Using PuTTY to SSH into the CentOS box, I can backspace for the read prompt without any issues.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .