« first day (84 days earlier)      last day (1476 days later) » 

7:03 AM
I have just been looking at the page again and thinking about how to improve my answer. The user might write "my name is Zainab and I'm a marine biologist"
 
One way you could improve your answer is to add the -r option to your read commands!
 
I will definitely do so haha
 
Thanks! :)
As for other changes, how far do you want to go? For example, do you want to make "My name is" autocomplete when Tab is pressed?
 
oh that would be amazing... I don't know how to do that!
would you like to answer this question?
 
I tried bash, zsh, mksh, lksh, and a new version of yash, all of which support shopt -o pipefail. None of them placed a different value in $? from a crash when it was placed there due only to pipefail being enabled than when it would be placed there anyway. This appears unique to ksh93, though the self-crashing behavior (raising a signal on exit when $? is higher than 256) also appears unique to ksh93.
The question we recently undeleted?
I wasn't thinking of doing so. Maybe. But I wouldn't post an answer about autocompletion.
The only sort of answer I'd be interested in posting there is something you would be better at posting: a sed solution. This covers the first branch, but not the second:
sed -rn 's/[Mm]y name is (.+)/hi, \1/p;q'
@Zanna I don't know how either, but I'm pretty sure it can be done, because in bash the read builtin use GNU Readline if the -e option is passed, and GNU Readline supports autocompletion.
Should I move some of these messages to the island?
 
7:33 AM
yeah, the discussion is getting increasing Islandy
 
I'll move some messages.
 
thank you... should be doing it myself!
 
Why?
I could have insisted on not also being made room owner for either of these rooms!
 
haha :)
 
Also, shouldn't I take some responsibility for the fact that trouble long-winded technical conversation tends to follow me around?
 
7:40 AM
haha it's a virtue
 
20 messages moved from Raiders of the Lost Downboat‌​
 
@EliahKagan second branch?
 
1 message moved from Raiders of the Lost Downboat‌​
Hmm, I can't move the most recent message posted in a room.
@Zanna It covers the if-suite but not the else-suite.
 
interesting...
@EliahKagan oh I see... hmm
 
Like that time I had selected the "20 messages moved to" message as well as the "haha it's a virtue" message. And the time before that, the "haha it's a virtue" message was the last one I had selected.
 
8:04 AM
elsed with sed... read -rp "Say something: "; answer=$(echo "$REPLY" | sed -rn 's/[Mm]y name is (.+)/Hi \1/p;q'); echo "${answer:=I did not understand you}"
 
@EliahKagan Darn, it looks like you actually can't customize autocompletion with read -e in bash:
28
Q: bash and readline: tab completion in a user input loop?

ataI'm making a bash script which presents a command line to the user. The cli code is as this: #!/bin/bash cmd1() { echo $FUNCNAME: "$@" } cmd2() { echo $FUNCNAME: "$@" } cmdN() { echo $FUNCNAME: "$@" } __complete() { echo $allowed_commands } shopt -qs extglob fn_hide_prefix...

@Zanna The goal is to bypass read, though.
 
oh!
 
Like to use just a single sed command for the entire thing.
 
hmm
 
@Zanna How do I make a Sed command run only if the preceding command failed to match something?
 
8:18 AM
hmm I don't know if there's a way to negate the t command
maybe eating something will inspire me... breakfast time
 
8:37 AM
@Zanna Well, this works:
sed -nr 's/[Mm]y name is (.+)/hi, \1/p; tQ; s/.*/I didn\x27t understand that/p; :Q; q'
It makes me feel like I'm programming in Cassette BASIC, but it works.
 
awesome!
lol
that makes sense - if it matched, Quit!
thanks for educating me :D
 
Well I'm quitting either way.
It's just that I skip over printing the error message if the first s command matched.
 
yeah I see that, you put your label at the end
 
I'm dissatisfied with this script though.
 
why?
 
8:45 AM
Is there no better way to print a string than using to s to match the whole line and replace it with it?
 
@EliahKagan (my first computer was a ZX Spectrum - the programs for that were on casette tapes too)
 
Whoa, that's much older than the first computer I used.
Well, older.
Actually I'm not sure when it was originally manufactured. I'll have to look into that.
 
I was 5. When I got slightly older I wrote programs for it that drew slightly animated pictures (copying from the book)
 
I never used a computer with a cassette drive, of the kind Cassette BASIC used. My first programming language was Cassette BASIC because it was built into the BIOS of the 8088 IBM PC. When the machine failed t boot to disk, it booted into Cassette BASIC. This was when I was five.
 
haha :)
 
8:52 AM
@Zanna I thought you had said that Bash was the only programming language you knew, except for special-purpose languages like Sed.
 
@EliahKagan well, you don't need to match the whole line to print it, but since we need to match that phrase and select part of it I don't think there is a better way...
@EliahKagan I don't remember that language :(
 
Oh.
You don't still have the printed manuals?
 
I doubt it. If I saw them, I think I would remember. It was very easy to understand
 
So that was Sinclair BASIC?
 
yesss!
:D
 
8:59 AM
There must be emulators for that hardware.
sudo apt install fuse-emulator-gtk
 
haha thanks so much!
@EliahKagan that colourful page border is referencing the way the screen looked while the program was loading. You got a window in the middle telling you what was happening (hopefully) and around it (behind it) these lines scrolling and jumping around, red and green or blue and yellow. It made a godawful noise the whole time this was happening, and it took ages
why do we remember these devices so lovingly? haha
@EliahKagan oh you mean the error message... damn, I am really slow
how are you giving it what the user typed anyway?
 
@Zanna sed reads from standard input when no path argument is passed.
 
9:20 AM
hmm o.O
I don't think you need your -n and p, but I am probably wrong
 
You're right. Because I'm substituting in both cases.
Is this Sed script portable? I don't think it is.
 
@EliahKagan oh I see! omg
I never thought about actually using this
@EliahKagan why not? I think -r works on 2 versions of sed, and -E works on 2 versions, but in GNU sed, both work
The t command and s command aren't GNU extensions
 
@Zanna You mean using the external command that processes user input in a script to read it as well?
 
@EliahKagan yes
 
@Zanna Oh, yeah. I recommend doing that anytime there isn't a compelling reason not to. Especially for reading in a loop.
 
9:33 AM
my ballet teacher used to say of me "she is the last one to get it, but then she never forgets"
She was right about the first part
 
9:54 AM
@Zanna Well... it doesn't work on my FreeBSD 11.1 system:
ek@Apok:~$ sed -r 's/[Mm]y name is (.+)/hi, \1/; tQ; s/.*/I didn\x27t understand that/; :Q; q'
sed: 1: "s/[Mm]y name is (.+)/hi ...": undefined label 'Q; s/.*/I didn\x27t understand that/; :Q; q'
This works though:
sed -r $'s/[Mm]y name is (.+)/hi, \\1/\ntQ\n s/.*/I didn\x27t understand that/\n:Q\nq'
Apparently where labels are concerned, not all seds accept ; to do the same thing as a newline
 
10:16 AM
I wouldn't have thought of that - good to know!
 
10:26 AM
Or with ' ' and literal newlines:
sed -r 's/[Mm]y name is (.+)/hi, \1/
tQ
s/.*/I didn'\''t understand that/
:Q
q'
 
Well, I might have thought of that accidentally, because I like to lay sed scripts out that way
gtg :S later
 
k ttyl!
 
 
1 hour later…
11:44 AM
I think Q is a valid command...
Bad connection
I'm glad you posted your answer :)
 
Thanks, so am I!
Q? Bad connection?
 
No my connection here is bad, messages may get scrambled
 
Ah.
 
I think Q is a command in GNU sed but I may be dreaming. If it is, I might not use it as a label, I mean.
 
Capital Q is a command?
 
11:49 AM
Gtg again
 
Yes, that's true, it is:
       Q [exit-code]
              Immediately  quit  the  sed  script  without processing any more
              input.  This is a GNU extension.
Is there a problem with using commands as labels in a Sed script? I didn't use lower-case q because it would be confusing as I was already using that.
 
 
1 hour later…
1:11 PM
No, no problem afaik! I think it's usual to use :a in the absence of a reason to use something else, and a is a command of course, and your Q is logical. I was only thinking of readability - I think it's a tiny bit distracting if the label is a command. But maybe worrying about the readability of a sed command is a waste of worry... If we wanted readability, we'd use another language haha
 
1:38 PM
I think readability does matter. Part of what I'm hoping to convey is that even when bash has facilities that directly support an operation, and the operation isn't naturally a stream-editing operation, it's still often clearer, better, and more robust to use sed for it. So clarity would help with that. Plus, I even brought up clarity in the post, while advocating against the $' ' way with \ns.
 
2:11 PM
Well I think the benefits of using Q as a label outweigh the possible costs :) I'm really happy that question got undeleted now
 

« first day (84 days earlier)      last day (1476 days later) »