Little Girl's Mostly Linux Blog

UserInput

User input

This page was last updated on September 29, 2013.

Example 1

  • Method 1:

    #!/bin/bash
    echo "This will ask your name and use your name when communicating with you.";
    echo;
    echo -n "What is your name? ";
    read response;
    echo;
    echo "Hello, $response!";
    echo;
    
  • Method 2:

    #!/bin/bash
    echo "This will ask your name and use your name when communicating with you.";
    echo;
    read -p "What is your name? " response;
    echo;
    echo "Hello, $response!";
    echo;
    

Example 2

  • Method 1:

    #!/bin/bash
    echo "This will change to the directory you specify and list its contents.";
    echo;
    echo -n "Enter the path to the directory: ";
    read response;
    cd $response;
    echo;
    echo "The contents of the directory are:";
    echo;
    ls;
    echo;
    
  • Method 2:

    #!/bin/bash
    echo "This will change to the directory you specify and list its contents.";
    echo;
    read -p "Enter the path to the directory: " response;
    echo;
    cd $response;
    echo "The contents of the directory are:";
    echo;
    ls;
    echo;
    

Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: