0

I'm trying to make this simple script:

  #!/bin/sh
  echo -en "What is your name [ `whoami` ] "
  read myname
  if [ -z "$myname" ]; then
          myname=`whoami`
  fi
  echo "Your name is: $myname"

What I want: to read my input in the same line as What is your name message is.

What I get( PROBLEM ): the console reading the input on a new line and taking the option -en as another string.

What I have tried: Change #!/bin/sh to #!/bin/bash and using only e as an option.

Why is this not working? Thank you for your time.

Skipydie
  • 23
  • 1
  • 7
  • You're not using `/bin/sh` as your interactive shell, so `echo` is different. – Barmar Jan 23 '20 at 01:03
  • Use `printf` instead of `echo`. – Barmar Jan 23 '20 at 01:03
  • @Barmar I though that `#!/bin/sh` makes my interactive shell `sh`. How can I set it correctly? Thank you for your time. – Skipydie Jan 23 '20 at 01:31
  • `#!/bin/sh` is the shell that runs the script, not the shell in your console. They have nothing to do with each other. – Barmar Jan 23 '20 at 01:32
  • The shebang is the shell that runs the script when you don't override it. When you do `sh myscript`, you override the shebang (so you should avoid this now and in the future for all scripts). See the duplicate for how to ensure that the script runs with the correct shell every time. – that other guy Jan 23 '20 at 01:36

0 Answers0