Find the answer to your Linux question:
Results 1 to 4 of 4
I'm new to bash scripting. I just cannot seem to find the answer anywhere. I've read some tutorials to get the taste of bash scripting but I haven't read enough ...
  1. #1
    Linux Enthusiast flipjargendy's Avatar
    Join Date
    Aug 2004
    Location
    Xanadu, Titan, Saturn
    Posts
    610

    Bash Script User Input...

    I'm new to bash scripting. I just cannot seem to find the answer anywhere. I've read some tutorials to get the taste of bash scripting but I haven't read enough yet.

    Right now I am trying to get some user input and add it to a variable. I want it to prompt the user on the same line that the prompt for input is on. For example:

    Enter the name: userInput

    but when I run the script it looks like this:

    [b]Enter the name:
    userInput

    Does anyoen know how I can fix my code to make it work how I want? Thanks.

    Code:
    echo "Enter the name that each file will be renamed to (ex. picture): "; read NAME;
    echo 
    echo "Enter the number you'd like to start at: "; read NUM;
    Running Linux Since 2001®
    Registered Linux User #430868 - Since 9•12•06

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Hi flipjargendy !

    Add -n after echo to disable new line.
    Code:
    echo -n "Enter the name that each file will be renamed to (ex. picture): "; read NAME;
    echo 
    echo -n "Enter the number you'd like to start at: "; read NUM;
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    hi,


    you can also do it as follows(with one command)
    Code:
    read -p "Enter the name that each file will be renamed to (ex. picture): " NAME
    and there you go
    Linux and me it's a love story

  4. #4
    Linux Enthusiast flipjargendy's Avatar
    Join Date
    Aug 2004
    Location
    Xanadu, Titan, Saturn
    Posts
    610
    Thanks guys.
    Running Linux Since 2001®
    Registered Linux User #430868 - Since 9•12•06

Posting Permissions

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