nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell script read in indented / menus

This is a discussion on Shell script read in indented / menus within the Shell scripting forums, part of the Development/Scripting category; Dear All I am writing a simple shell script of menu options. Here is an extract: echo " Press 1-5 ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-05-2009, 05:40 PM
Junior Member
User
 
Join Date: May 2009
OS: kubunto 8.10
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
stephanos is on a distinguished road
Default Shell script read in indented / menus

Dear All

I am writing a simple shell script of menu options. Here is an extract:
echo " Press 1-5 or 9, then press Enter [ ]"
echo ""
read i

What I would like to do is arrange for the cursor to be after the word Enter ans between the [ and ].

Is this possible?

Thanks and wait to hear

Stephanos
Reply With Quote
  #2 (permalink)  
Old 08-05-2009, 06:25 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Noop. Shell lacks cursor movement, try something as follows:
Code:
 read -p "Press 1-5 or 9, then press Enter : " i
However, you can jazz up a bit using dialog utility from a shell script and it works with cli as well as GUI
Code:
dialog --menu "Select choice" 15 30 3 1 Choice1 2 Choice2 3 Choice3 4 Choice4 5 Choice5 6 Exit
Here is a sample shell script:
Code:
#!/bin/bash
ansfile=/tmp/file.$$
height=15
width=40
menu_height=5
title="Main Menu"
dialog  --clear \
    --title "$title" \
    --menu "Select choice" $height  $width $menu_height  \
    1 "Choice1" \
    2 "Choice2" \
    3 "Choice3" \
    4 "Choice4" \
    5 "Choice5"  2>$ansfile

ret=$?
ans=$(cat $ansfile)

case $ret in
  0)
    echo "You selected $ans";;
  1)
    echo "[Cancel] key pressed.";;
  255)
    echo "[ESC] key pressed.";;
esac

/bin/rm -f $ansfile
Attached Images
File Type: jpg Screenshot.jpg (20.4 KB, 4 views)
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 09-05-2009, 12:48 AM
Junior Member
User
 
Join Date: May 2009
OS: kubunto 8.10
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
stephanos is on a distinguished road
Default Shell script read in indented / menus

Dear nixcraft

thanks, done, problem solved, well done

stephen
Reply With Quote
Reply

Tags
dialog , shell script menu , shell script to display dialog boxes , shell scripting


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
FTP SHELL Script gsb1bee Shell scripting 3 24-04-2009 05:32 PM
Script to open and read a file that is supplied as a command line arg blingbling Shell scripting 3 31-03-2009 10:54 AM
shell script for ftp chaharvikram Shell scripting 0 09-10-2008 06:24 PM
Binary Conversion Of Shell Script (shell script compiler) chandanperl Shell scripting 3 29-07-2008 10:22 AM
writing a shell script to find out my shell name jaymob123 Shell scripting 1 08-10-2007 12:36 AM


All times are GMT +5.5. The time now is 06:48 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38