select function for ash

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

select function for ash

#1 Post by Karl Godt »

Bash has the select function, ash (of course) not .

So I want to write one for the init in the initrd.gz

So far it works quite well, except when the selected line contains IFS chars (spaces):

Code: Select all

select(){
#bash:select PUPPY_SAVE_TO_LOAD in $SAVE_FILES ;do :;break;done
#bash:select PUPPY_SFS_TO_LOAD in $CHOOSE_PUP ;do :;break;done
[ "$1" -a "$2" = in -a "$3" ] || return 0
local NUMBER CONTENT c CHOICE
for content in "$3" ; do
c=$((c+1))
CONTENT="$CONTENT
   ${c}:$content"
done
echo  "$CONTENT"
read -p '? :' -n 1 -t 20 NUMBER
echo
[ "$NUMBER" ] || NUMBER=1
CHOICE=`echo "$CONTENT" | grep -w "^   $NUMBER" | cut -f2 -d:`
echo \$1=$1 CHOICE=$CHOICE
#IFS='' eval `echo ${1}=$(echo "$CHOICE")`
#eval ${1}="$CHOICE"
#IFS="·" eval ${1}="$CHOICE"
#PATTERN="\${1}=$CHOICE"
eval "$PATTERN"
#eval `echo \${1}="$CHOICE"`
}
Mainly eval chokes . Any ideas ?

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#2 Post by Karl Godt »

Seems solved :

Code: Select all

eval "${1}=\"$CHOICE\""
was
eval ${1}="$CHOICE"
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#3 Post by jpeps »

Karl Godt wrote:Seems solved :

Code: Select all

eval "${1}="$CHOICE""
was
eval ${1}="$CHOICE"
(Kindof) similar bug I found recently:

Code: Select all

[ "${b}">0 ]      redirect
[ "${b}>0" ]      greater than

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post by Karl Godt »

Hmm .. > as -gt greater than seems not to work for me in both .

# b=10
# [ $b > 10 ] && echo bigger than 10 || echo not bigger than 10
bigger than 10
# [ "$b" > 10 ] && echo bigger than 10 || echo not bigger than 10
bigger than 10
# [ "$b"> 10 ] && echo bigger than 10 || echo not bigger than 10
bigger than 10
# [ "$b">10 ] && echo bigger than 10 || echo not bigger than 10
bigger than 10
# ash
# b=10
# [ $b > 10 ] && echo bigger than 10 || echo not bigger than 10
bigger than 10
# [ "$b" > 10 ] && echo bigger than 10 || echo not bigger than 10
bigger than 10
# [ "$b"> 10 ] && echo bigger than 10 || echo not bigger than 10
bigger than 10
# [ "$b">10 ] && echo bigger than 10 || echo not bigger than 10
bigger than 10
# [ "$b > 10" ] && echo bigger than 10 || echo not bigger than 10
bigger than 10

~

test [ brackets need spaces between the three operators , otherwise they don't work as intended in my observations .

Post Reply