ibzrg470
06-12-2005, 12:24 PM
something I wrote to pass the time at work....
You can input any command you want at the first case option, for now it just runs and ls -l against the file you choose.
I'm going to use it for running snes roms.
The script handles spaces with no problem, but it gets hung up on files with numbers in it because grep finds the first instance of the expression.
Enjoy!
#!/bin/sh
#-------------------
# Variables
#-------------------
MENLOOP1=1
SELECTION=NONE
CHOICE=NONE
#-------------------
# Generate Menu
#-------------------
while [ $MENLOOP1 -eq 1 ] ;do
echo 'possible selections'
ls |cat -b
echo 'type your selection and press [enter]'
read SELECTION
CHOICE=`ls |sed 's/ /:/g'| cat -b |grep $SELECTION |head -1 |awk '{print $2}'|sed 's/:/ /g'`
echo 'you selected:' $CHOICE
echo 'is this correct? (y/n)'
echo 'type quit to end this program'
read ANS
case $ANS in
y|yes)
echo 'ok thanks'
MENLOOP1=0
ls -l |grep "$CHOICE"
;;
n|no)
echo 'Pleas choose again'
MENLOOP1=1
;;
quit)
echo 'bye now'
MENLOOP1=0
;;
esac
done
#----------------------------------
# Thanks for using my script !!
#----------------------------------
You can input any command you want at the first case option, for now it just runs and ls -l against the file you choose.
I'm going to use it for running snes roms.
The script handles spaces with no problem, but it gets hung up on files with numbers in it because grep finds the first instance of the expression.
Enjoy!
#!/bin/sh
#-------------------
# Variables
#-------------------
MENLOOP1=1
SELECTION=NONE
CHOICE=NONE
#-------------------
# Generate Menu
#-------------------
while [ $MENLOOP1 -eq 1 ] ;do
echo 'possible selections'
ls |cat -b
echo 'type your selection and press [enter]'
read SELECTION
CHOICE=`ls |sed 's/ /:/g'| cat -b |grep $SELECTION |head -1 |awk '{print $2}'|sed 's/:/ /g'`
echo 'you selected:' $CHOICE
echo 'is this correct? (y/n)'
echo 'type quit to end this program'
read ANS
case $ANS in
y|yes)
echo 'ok thanks'
MENLOOP1=0
ls -l |grep "$CHOICE"
;;
n|no)
echo 'Pleas choose again'
MENLOOP1=1
;;
quit)
echo 'bye now'
MENLOOP1=0
;;
esac
done
#----------------------------------
# Thanks for using my script !!
#----------------------------------