Explore BrainMass
Share

Explore BrainMass

    How to Write Interactive Unix Shell Scripts using Case

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    1. Use "vi" to create a shell script copying the following:

    #!/bin/bash
    echo Select a country from the following list:
    echo America, Italy, France, Germany
    read country

    case $country in
    [Aa]merica ) echo Ford; echo Perhpas;;
    [Ii]taly ) echo Ferarri; echo no;;
    [Ff]rance ) echo Peugeot ;echo no way;;
    [Gg]ermany ) echo Porsche ;echo yes;;

    esac

    · Run the shell script.

    2. Create your own shell script that completes the following problem:

    § Ask the user their name

    § Compare it to your name

    § Give a reply that their response is either your name too or it is a nice name too.

    © BrainMass Inc. brainmass.com October 9, 2019, 7:39 pm ad1c9bdddf
    https://brainmass.com/computer-science/software-development/how-to-write-interactive-unix-shell-scripts-using-case-125018

    Solution Preview

    1. After creating the first shell script it shows the following input / output that were tried on a unix shell prompt ">>"

    >>./shScript.sh
    Select a country from the following list:
    America, Italy, France, Germany
    America
    Ford
    Perhpas
    >>/shScript.sh ...

    Solution Summary

    There are two parts of the solution. The first part just executes a pre-defined script.
    The second part creates a working shell script to address the following problem.
    Creates a shell script that completes the following problem:

    § Ask the user their name

    § Compare it to your name

    § Give a reply that their response is either your name too or it is a nice name too.

    The script asks for user's name, then compares with the name stored into a variable $myname inside the script. You can change it's value to anything just make sure you surround it with quotes.

    $2.19