Find the answer to your Linux question:
Results 1 to 2 of 2
Using read to prompt for editable user input in Bash 3 Below is a simple script to prompt for user input while suggesting an editable default value at the prompt: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    15

    Using read to prompt for editable user input in Bash 3


    Using read to prompt for editable user input in Bash 3
    Below is a simple script to prompt for user input while suggesting an editable default value at the prompt:


    Code:
    shortname=user1
    
    read -e -i $shortname -p "Please enter the username you would like to add: " input
    USERNAME="${input:-$shortname}"


    Output:

    Please enter the username you would like to add: user1

    The above is the expected and working output in BASH 4

    If I try this same code in BASH 3 it doesn't work because this version does not support the "-i" switch.

    I need some help getting the same result in BASH 3.
    Thanks

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by woodson2 View Post
    Using read to prompt for editable user input in Bash 3
    Below is a simple script to prompt for user input while suggesting an editable default value at the prompt:


    Code:
    shortname=user1
    
    read -e -i $shortname -p "Please enter the username you would like to add: " input
    USERNAME="${input:-$shortname}"


    Output:

    Please enter the username you would like to add: user1

    The above is the expected and working output in BASH 4

    If I try this same code in BASH 3 it doesn't work because this version does not support the "-i" switch.

    I need some help getting the same result in BASH 3.
    Thanks
    Hi,

    Take a look at the bottom solution posted at this SO thread:

    http://stackoverflow.com/questions/1...nt-users-input

    You'll have to muck with it a bit, but it is trying to do something similar to what you want.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •