Προς το περιεχόμενο

[INFO] Η δύναμη της Κονσόλας


Manos-Sx

Προτεινόμενες αναρτήσεις

  • Απαντ. 889
  • Δημ.
  • Τελ. απάντηση

Συχνή συμμετοχή στο θέμα

Εννοεί if [[ "$REPLY" = "" ]] .

Όταν χρησιμοποιείς το [ χρησιμοποιείς απευθείας την test command (σαν alias είναι ουσιαστικά) που έχει άλλο τρόπο για να αναγνωρίζει το enter (δεν θυμάμαι πως). Το [[ για τους ελέγχους είναι built-in του bash.

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

Εννοώ κάτι τέτοιο:

 

echo "Enter key"
    read -n 1 REPLY
list=(koko kiki kaka)
select c in ${list[@]}; do
  if [[ "$REPLY" = "q" ]] || [[ "$REPLY" = "Q" ]]; then
    exit
  elif [[ "$REPLY" = [0-9]* ]] && [[ "$REPLY" -gt 0 ]] && [[ "$REPLY" -le ${#list[@]} ]]; then
    kk="$c"
    break
  else
    break
  fi
done

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

δεν καταλαβατε.
 
δεν θελω να χρησιμοποιήσω την read.
 
θελω στο παραδειγμα οπως ακριβως το εδωσα, οταν παταω σκετο enter να κανει break η loop.

δηλαδη κατι μεσα στην λουπα που να λεει οτι αν η REPLY ειναι σκετο enter κανε break.

γινεται?

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

μεσα στην select, buildin variable ειναι

 

Also applicable to select menus, but only supplies the item number of the variable chosen, not the value of the variable itself.

 

οτι δινω μπαινει στην REPLY και κανω τους ελεγχους μου.

Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

αυτο εννοεις?

 

if [[ "$REPLY" = "Enter" ]]

 

αν ναι, nope. :(

 

ουτε αυτο παιζει.

 

θελω στο παραδειγμα οπως ακριβως το εδωσα, οταν παταω σκετο enter να κανει break η loop.

 

δηλαδη κατι μεσα στην λουπα που να λεει οτι αν η REPLY ειναι σκετο enter κανε break.

 

γινεται?

select name [ in word ] ; do list ; done

The list of words following in is expanded, generating a list of

items. The set of expanded words is printed on the standard

error, each preceded by a number. If the in word is omitted,

the positional parameters are printed (see PARAMETERS below).

The PS3 prompt is then displayed and a line read from the stan‐

dard input. If the line consists of a number corresponding to

one of the displayed words, then the value of name is set to

that word. If the line is empty, the words and prompt are dis‐

played again. If EOF is read, the command completes. Any other

value read causes name to be set to null. The line read is

saved in the variable REPLY. The list is executed after each

selection until a break command is executed. The exit status of

select is the exit status of the last command executed in list,

or zero if no commands were executed.

% cat tmp.sh 
#!/bin/bash
list=(koko kiki kaka)

select c in ${list[@]}; do
	echo REPLY is $REPLY
  if [ "$REPLY" = "q" ] || [ "$REPLY" = "Q" ]; then
    exit
  fi
done

% ./tmp.sh 
1) koko
2) kiki
3) kaka
#? 1
REPLY is 1
#? k
REPLY is k
#? <--- Edo einai to enter
1) koko
2) kiki
3) kaka
#? q
REPLY is q
Στην περίπτωση του enter δεν εμφανίζεται καθόλου το μήνυμα "REPLY is τάδε". Αυτό, σε συνδυασμό με την manpage του bash, μου δίνουν την εντύπωση ότι το enter το δουλεύει εγγενώς η select και δεν πάει καθόλου μέσα στο σώμα του βρόχου. Μπορεί να κάνω λάθος φυσικά.
  • Like 4
Συνδέστε για να σχολιάσετε
Κοινοποίηση σε άλλες σελίδες

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...