Results 1 to 4 of 4

Thread: Simple Script "space" problem

  1. #1
    Join Date
    May 2005
    Location
    St.Catharines, Ontario
    Beans
    351
    Distro
    Ubuntu Development Release

    Simple Script "space" problem

    Here is a simple menu script but how do I get rid of the space
    between Start and Backup?
    Obviously I am getting three options listed instead of two:
    Start
    Backup
    Quit

    OPTIONS="Start Backup Quit"
    select opt in $OPTIONS; do
    if [ "$opt" = "Start Backup" ]; then
    echo "start backup"
    exit
    elif [ "$opt" = "Quit" ]; then
    echo done
    else
    clear
    echo bad option
    fi
    done

    But I want Start Backup to be one option.
    I am new to this and learning a little here and a little there.
    I search google but couldn't find the answer.
    Thanks.
    Sign-up to Dropbox using the following link and get 2.25GB of storage FREE!!!
    https://www.dropbox.com/referrals/NTM2NDgxOTc5

  2. #2
    Join Date
    May 2007
    Location
    Pleasant Hill, California
    Beans
    315
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Simple Script "space" problem

    Did you try a backslash before the space? That's one common way to enter spaces - the backslash "escapes" the space.

    Just one blind man trying to lead another here.

  3. #3
    Join Date
    Jun 2007
    Beans
    48
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Simple Script "space" problem

    The easy way would be to change the space to either - or _

    Code:
    OPTIONS="Start-Backup Quit"
    
    select opt in $OPTIONS; do
    	if [ "$opt" = "Start-Backup" ]; then
    		echo "start backup"
    		exit
    	elif [ "$opt" = "Quit" ]; then
    		echo done
    		exit
    	else
    		clear
    		echo bad option
    	fi
    done
    My new blog Free and Priceless --- It's filled with wholesome Ubuntu goodness!!!

  4. #4
    Join Date
    Jun 2007
    Beans
    48
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Simple Script "space" problem

    The harder way:

    If you don't feed the in list option to select, it takes its options from the command line arguments.
    It just so happens that set -- "Start Backup" Quit will set $1 to Start Backup and $2 to Quit

    Therefore:
    Code:
    set -- "Start Backup" Quit
     
    select opt; do
    	if [ "$opt" = "Start Backup" ]; then
    		echo "start backup"
    		exit
    	elif [ "$opt" = "Quit" ]; then
    		echo done
    		exit
    	fi
    done
    will get you an option with a space in it. Also remember that if you set PS3= a string, the string will follow your menu as a prompt.
    Code:
    PS3="Begin backup now: "
    set -- "Start Backup" "No, Quit"
    select opt; do
    	if [ "$opt" = "Start Backup" ]; then
    		echo "Starting backup"
    		exit
    	elif [ "$opt" = "No, Quit" ]; then
    		echo done
    		exit
    	fi
    done
    gets me:

    Code:
    1) Start Backup
    2) No, Quit
    Begin backup now: 1
    Starting backup
    Hope this helps!
    My new blog Free and Priceless --- It's filled with wholesome Ubuntu goodness!!!

Bookmarks

Posting Permissions

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