Wikipedia:Reference desk/Archives/Computing/2022 March 15
Computing desk | ||
---|---|---|
< March 14 | << Feb | March | Apr >> | March 16 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
March 15
editNotepad weirdness
editI discovered that if I copy the following text from a Wikipedia page:
<math>12345
and then try to paste it into Windows Notepad, nothing happens. There has to be five or more characters after the math tag:
<math>This won't paste either.
So the following will paste:
<math>OK!
If there are extra characters at the start of the string it works fine:
I can copy and paste this alright<math>1234567
So is this a wrinkle in Notepad, or in MediaWiki? Why is it? Card Zero (talk) 09:54, 15 March 2022 (UTC)
- Everything pastes OK for me. Which version of Windows are you using, because that will define which version of Notepad you have. I'm on Windows 10(21H2) - X201 (talk) 09:57, 15 March 2022 (UTC)
- Windows 11. I was going to mention that, but then I thought, no, that won't alter which version of Notepad I have. Card Zero (talk) 09:59, 15 March 2022 (UTC)
- If Windows Notepad is the only application that does not let you paste this – I assume you have tried other places that usually allow the pasting of text, such as your browser's address bar – this is obviously a snafu in (your version of) Windows Notepad, unrelated to MediaWiki. --Lambiam 10:15, 15 March 2022 (UTC)
- Yep, must be Notepad. (Version 10.0.22000.1, but a lot of components of Windows have that version string and I'm not sure how meaningful it is.) It's oddly specific. Could it be a crude way to protect again some kind of code injection? It's not like Notepad interprets tags, though, or is capable of running anything (presumably not even VBScript), so that doesn't really make sense. (A further oddity is that I can copy and paste the string within Notepad: so it must be something that happens when the clipboard is imported.) Card Zero (talk) 10:25, 15 March 2022 (UTC)
bash i/o redirection
edithello,
I want to pipe the output of a command to a function, but the function should be able to also read from the terminal:
func1() {
while read line #from the pipe
do
...
if read -n1 key; ... fi #from the terminal
done
}
seq 10 | func1
Is there an easy way to do this? I assume it's something to do with exec
and creating one's own file descriptors... Aecho6Ee (talk) 12:41, 15 March 2022 (UTC)
- Here's a Stack Exchange answer which suggests using /dev/tty. Card Zero (talk) 16:03, 15 March 2022 (UTC)
seq
is non-standard and totally unnecessary in a shell; any non-ancient shell can count numbers for you. See here. If you're trying to teach yourself shell scripting, use this and the official bash (or other shell) documentation instead of the University of Google, because there is sooooo much terrible stuff out there that keeps getting transmitted by the copy-and-paste programming technique—for instance, "make a loop by using seq and piping it to something", which is the source of your trouble here. Use afor
loop instead, as the linked content details, and your trouble is gone. --47.147.118.55 (talk) 06:01, 16 March 2022 (UTC)- There's also Bash Reference Manual published by GNU which is pretty authoritative. Probably not beginner level though, but a valuable reference to have on a bookmark somewhere. Martin of Sheffield (talk) 10:55, 16 March 2022 (UTC)
- thank you so much everyone. I went with duplicating stdin (
exec 3<&1
) andread
ing from the copy. 47.147....: seq was purely for illustration. Aecho6Ee (talk) 18:36, 16 March 2022 (UTC)- When asking for assistance, tell us the actual problem instead of a made-up one. There might be a better way to do what you want. --47.147.118.55 (talk) 06:55, 19 March 2022 (UTC)
- No, that really was it - how can a function read from a pipe and the tty at the same time. Thanks again. Aecho6Ee (talk) 16:35, 21 March 2022 (UTC)
- Sometimes the made-up, abstract problem is the actual problem. :) Then sometimes question-answerers derail it, and answer a different question which is much more sensible, and education is defeated. Or on the other hand it could be an XY problem like you said, could go either way, best not to assume. Card Zero (talk) 01:44, 23 March 2022 (UTC)
- When asking for assistance, tell us the actual problem instead of a made-up one. There might be a better way to do what you want. --47.147.118.55 (talk) 06:55, 19 March 2022 (UTC)
- thank you so much everyone. I went with duplicating stdin (
- There's also Bash Reference Manual published by GNU which is pretty authoritative. Probably not beginner level though, but a valuable reference to have on a bookmark somewhere. Martin of Sheffield (talk) 10:55, 16 March 2022 (UTC)