4 ms·
Doesn't work for me on linux using 5.1.8(1)-release (x86_64-pc-linux-gnu). Output with `set -vx` at top (I guessed "fooba"): ++ [[ false != true ]] ++
by seanp2k2 5y ago
Doesn't work for me on linux using 5.1.8(1)-release (x86_64-pc-linux-gnu). Output with `set -vx` at top (I guessed "fooba"):
++ [[ false != true ]]
++ guess_count=1
++ [[ 1 -le 6 ]]
++ echo 'Enter your guess (1 / 6):'
Enter your guess (1 / 6):
++ read guess
fooba
+++ echo fooba
+++ tr '[a-z]' '[A-Z]'
++ guess=FOOBA
[... ÉTUDE =~ FOOBA ]]
++ echo 'Please enter a valid word with 5 letters!'
Please enter a valid word with 5 letters!
++ guess_count=0
++ [[ false != true ]]
++ guess_count=1
++ [[ 1 -le 6 ]]
++ echo 'Enter your guess (1 / 6):'
Enter your guess (1 / 6):
++ read guess
- huydotnet 5y agoI think it's something with the `/usr/share/dict/words` file, I made a comment in the gist to update the code to the actual english dictionary words, could you try that?
- berkes 5y agoI've replied to your comment on GH, The problem is likely due to how your symlinks are set-up. Which is an artifact of your systems' locales. Easiest is to check /usr/share/dict with `ls -hal`. Do read the README there, before manually flipping symlinks around, though.
- ragingrobot 5y agoPerhaps allowing the user to specify a word list, and defaulting to some value would be better than suggesting symlinks. On Tumbleweed, I have no /usr/share/dict/words, but /use/share/dict/american. Allowing the user to set would also be useful if multiple languages are installed, and doesn't change the number of lines of code. I changed the first line to: words=$(grep -Ex '\w{5}' "/usr/share/dict/${wordlist:=words}" | tr '[a-z]' '[A-Z]') so I can invoke it wordlist=american wordle.sh You can also replace it with $1 (or any other positional parameter): words=$(grep -Ex '\w{5}' "/usr/share/dict/${1:=words}" | tr '[a-z]' '[A-Z]') And invoke it with wordle.sh american In either case, it defaults to /usr/share/dict/words if no list is given. Personally I'd go with the first as you use $1 for guesses, and higher numbered parameters get messy.
- berkes 5y agoIn more UNIXy tradition, I'd say either pipe in a file, or pick the default. That way people can use downloaded files too.
- ragingrobot 5y agounfortunately using a simple pipe is not going to work, because you're also looking for user input, and you can't do both easily with stdin.
- seanp2k2 5y agoIt’s possible to construct parallel (ish) pipeline processing in bash by using file descriptors above 2. See https://mywiki.wooledge.org/FileDescriptor https://mywiki.wooledge.org/FileDescriptor . It’s part of why I always liked Ruby’s .tap() : https://medium.com/aviabird/ruby-tap-that-method-90c8a801fd6a https://medium.com/aviabird/ruby-tap-that-method-90c8a801fd6...