LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2010, 03:43 AM   #1
webhope
Member
 
Registered: Apr 2010
Posts: 184

Rep: Reputation: 30
Select order


Hi, I have some problem with displaying items of select. All items shoul be on separete line.

Code:
clear; IFS="\n";
    job=('Rename a file ' "move" "copy" "find" "view" "edit"  "next");
    echo -e $AUTO_FINISH$'\E[1;37mJob:\E[1;0m';
    select vyber in "${job[@]}"; do
	case $vyber in
	  ${job[0]}) krok="rename"; ;;
	  ${job[1]}) krok="move"; ;;
	  ${job[2]}) krok="copy"; ;;
	  ${job[3]}) krok="find"; ;;
	  ${job[4]}) krok="view"; ;;
	  ${job[5]}) krok="edit"; ;;
	  ${job[6]}) krok="continue";  break; ;;
	esac;
    done;
My output:
Code:
Job:
1) Rename a file   3) copy            5) view            7) next
2) move            4) find            6) edit
I Can find out whats wrong
 
Old 04-26-2010, 04:05 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Take a look at the COLUMNS bash variable. You can try to set it to a low value, before the select construct.
 
Old 04-26-2010, 04:15 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Nothing is wrong! The select statement is working as expected (assuming the prompt to choose one of the options was snipped from what you posted).
 
1 members found this post helpful.
Old 04-26-2010, 04:21 AM   #4
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by catkin View Post
Nothing is wrong! The select statement is working as expected (assuming the prompt to choose one of the options was snipped from what you posted).
But problem is I want every line separate. If I change 'Rename a file ' to 'Rename' everhing is ok. However if spaces are included then it makes trouble.

I try to find something about COLUMNS variable but nothing valuable I have.

Last edited by webhope; 04-26-2010 at 04:23 AM.
 
Old 04-26-2010, 04:53 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
I try to find something about COLUMNS variable but nothing valuable I have.
Take a look at man bash under the "Shell variables" section.
 
1 members found this post helpful.
Old 04-26-2010, 05:02 AM   #6
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
All I found:

COLUMNS
Used by the select builtin command to determine the terminal width when printing
selection lists. Automatically set upon receipt of a SIGWINCH.

Clever
It works
COLUMNS='\n'
Thanks

Last edited by webhope; 04-26-2010 at 05:04 AM.
 
Old 04-26-2010, 05:13 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
The behaviour of select is not defined. Here's a "roll-your-own" alternative
Code:
job=('Rename a file ' 'move' 'copy' 'find' 'view' 'edit'  'next')

while true
do
    echo 'Choose by number...'
    for (( i=0; i<${#job[*]}; i++ ))
    do
        echo "$i ${job[i]}"
    done
    read
    if [[ ! $REPLY =~ ^[0-9]+$ || $REPLY -lt 0 || $REPLY -ge ${#job[*]} ]]; then
        echo "Invalid choice '$REPLY'".  Try again.
    else
        break 2
    fi
done

# $REPLY holds job index
 
Old 04-26-2010, 06:14 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by webhope View Post
It works
COLUMNS='\n'
Good it works. Anyway, COLUMNS should be set to a number of columns, not a character. The alternative suggested by Catkin should fit your needs, as well.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can I set the cups output order to always print in reverse order Thane Ubuntu 3 07-09-2018 09:49 PM
[SOLVED] MYSQL select ORDER BY, GROUP BY together sqn Programming 5 04-19-2010 06:07 AM
System suddenly changing disk order from BIOS order hscast Fedora 2 02-16-2010 09:09 PM
Select() did not select my socket thvo Programming 1 05-08-2005 12:20 AM
[PHP+MySQL] Rotate order in SELECT pnh73 Programming 5 12-31-2003 04:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration