#qa | Logs for 2020-12-02

« return
[12:50:46] <Bytram> TheMightyBuzzard: over here
[12:50:49] <Bytram> mkdir foo; cd foo; touch "bar" ; touch "buzz and bazz" ; ls -l ; for f in $(ls -quoting-style=shell) do; echo ${f} ; done
[12:52:17] <Bytram> ^^^ does not work, nor do any of the permutations of ls --quoting-style= that I have tried.
[12:54:44] <Bytram> coffee++ biab
[13:04:07] <TheMightyBuzzard> Bytram, gimme a few to get covfefe made and some nicotine in me and i'll be back
[13:15:02] <TheMightyBuzzard> Bytram, you're over complicating that. try: for f in *; do echo "${f}"; done
[13:16:17] <Bytram> that helps
[13:16:53] <TheMightyBuzzard> or the original one: for f in *; do echo cp -p "${f}" "${f}.orig" ; done
[13:17:46] <Bytram> not quite... lost quoting
[13:18:03] <TheMightyBuzzard> how's that?
[13:18:06] <Bytram> cp -p bar bar.orig
[13:18:06] <Bytram> cp -p buzz and bazz buzz and bazz.orig
[13:18:59] <TheMightyBuzzard> not seeing what you mean
[13:19:17] <Bytram> I have *two* files
[13:19:23] <TheMightyBuzzard> kay
[13:19:32] <Bytram> look at the 2nd generated command
[13:19:45] <Bytram> cp -p buzz and bazz buzz and bazz.orig
[13:19:53] <Bytram> that's not going to work
[13:19:59] <TheMightyBuzzard> oh, you want two cps?
[13:20:07] <Bytram> da!
[13:20:12] <Bytram> nah
[13:20:24] <TheMightyBuzzard> paste ls -l and tell me zactly what you want done
[13:20:32] <Bytram> cp -p "buzz and bazz" "buzz and bazz.orig"
[13:21:00] <Bytram> syntax ia prolly wrong with that
[13:21:12] <TheMightyBuzzard> oh, the above should work. works all the time for me doing encodes with spaces. echo is eating your quotes.
[13:21:23] <Bytram> cp -p 'buzz and bazz' 'buzz and bazz.orig'
[13:22:18] <TheMightyBuzzard> remove the echo and see if it don't work
[13:23:07] <Bytram> just did... and it worked... but I'm trying to grok why the echo looks the way it does
[13:23:28] <Bytram> cuse it looks like it shold not work
[13:23:45] <TheMightyBuzzard> cause echo eats the quotes. try it manually and see.
[13:23:59] <TheMightyBuzzard> try the echo line i mean
[13:24:26] <Bytram> realize, I'm trying to come up with a set of general concepts and syntaxes that I can generally apply
[13:25:03] <Bytram> thas what i pasted before
[13:25:58] <TheMightyBuzzard> echo uses the quotes. if you want the quotes to remain you need to add some escaped quotes like "\"${f}\""
[13:26:36] <Bytram> pondering
[13:27:04] <TheMightyBuzzard> s'cause echo can do multi-line and other such like. the quotes are necessary for some of the stuff it can do.
[13:27:25] <TheMightyBuzzard> like echo "$foo >./bar;"
[13:28:01] <Bytram> that helps...
[13:28:02] <TheMightyBuzzard> so it consumes quotes
[13:28:38] <Bytram> does not help that filenames can *contain* single and double quotes
[13:28:51] <TheMightyBuzzard> oh that's not an issue
[13:28:58] <Bytram> echo this is a test > "filename"
[13:29:13] <TheMightyBuzzard> you can have any characters you want inside a variable and if you quote the variable it'll come out right
[13:29:35] <Bytram> echo this is a test > \"filename\"
[13:30:06] <TheMightyBuzzard> nope, the unquoted > will redirect to a filename with literal quotes
[13:30:50] <Bytram> my brain hurts
[13:31:31] <TheMightyBuzzard> tab completion will show you on any particular file if you're curious but you can have freaking newlines and nulls in a filename and for f in *; do touch "$f"; done will work
[13:32:47] <Bytram> okay, I need that, thankyoubut
[13:33:00] <Bytram> I'm a qa guy
[13:33:23] <Bytram> when trying something new, I like to display what I am about to do before I do it.
[13:33:25] <TheMightyBuzzard> $f and ${f} are the same thing but it's easier to do things like ${f}suffix and not have it interpreted as a variable named $fsuffix
[13:33:34] <TheMightyBuzzard> heh, yeah
[13:33:39] <Bytram> maybe even redirect to a file
[13:33:44] <Bytram> which I can review
[13:33:48] <Bytram> bless
[13:33:51] <Bytram> and then run
[13:34:44] <TheMightyBuzzard> that means you're gonna hafta learn about escaping quotes. actually makes life a little harder.
[13:35:09] <TheMightyBuzzard> hrm...
[13:36:23] <Bytram> so, I'm getting there (thanks to your help!) ... but I've had enough surprises where what I think is going to happen... does not. Hence the desire to make explicit my intention, and then try it.
[13:36:53] <Bytram> also very handy for debugging!
[13:37:57] <TheMightyBuzzard> yeah, printing out the command before executing it exactly as it's going to run isn't as easy as just running it.
[13:38:36] <Bytram> so, good to know that I am a bit flummoxed for a reason!
[13:40:24] <TheMightyBuzzard> but if you already know that echo is going to eat quotes, you can do something like echo "AA${foo}AA" and know that the AAs are marking the boundaries of the variable and quoting would take care of it in the actual command.
[13:40:28] <chromas> Also need to learn the different types of quotes :)
[13:40:52] <TheMightyBuzzard> "i drank what" -- socrates
[13:40:52] <Bytram> kinda related, and going on ancient memory. Had a contract ~20+ years ago. I think it was the C shell we were using. there was a way to invoke the shell so that a copy of all inputs and outputs could be copied to a file as I went.
[13:41:31] <TheMightyBuzzard> Bytram, fuck if i know. never remotely wanted such a bit of overkill.
[13:41:37] <Bytram> nod nod, I've done similar before, good to be reminded
[13:42:44] <Bytram> when freeform beating on code, is nice to try things and when stuff goes *boom* to have a record of how I got there. not just the commands (there's history) but the output, too.
[13:43:35] <Bytram> you've given me a bunch to chew on.
[13:43:36] <TheMightyBuzzard> nod nod. finding out how to screw things up is useful. unless you're trying to get something important done.
[13:43:59] <TheMightyBuzzard> you really want some headaches, wait until you realize the utility of the find command
[13:44:09] <Bytram> then you leave the screwed-up-detection to the users^W QA
[13:44:15] <Bytram> ;)
[13:44:31] <Bytram> oh been doing that all along
[13:45:12] <TheMightyBuzzard> xargs is another fun and useful one
[13:45:20] <Bytram> wish I could tell it to look for a name pattern with no concern for case sensitivity
[13:45:35] <Bytram> find . -type f | grep -i foo
[13:46:06] <TheMightyBuzzard> find . -type f -iname "whatever"
[13:46:18] <Bytram> O_O
[13:46:19] <TheMightyBuzzard> iname == case insensitive shell matching
[13:46:27] <TheMightyBuzzard> as opposed to -name
[13:46:34] <Bytram> can I use wildcards?
[13:46:37] <TheMightyBuzzard> yup
[13:46:40] <TheMightyBuzzard> or partials
[13:46:43] <TheMightyBuzzard> or whatever
[13:47:04] * chromas hears the gears turning in Bytram's head
[13:47:17] * chromas sprays some lube
[13:47:27] <TheMightyBuzzard> sorry, not partials
[13:47:28] <Bytram> find . -type f -iname "*something*"
[13:47:31] <TheMightyBuzzard> yar
[13:48:08] <TheMightyBuzzard> like -iname ".exe" no work but "*.exe" do
[13:48:22] <TheMightyBuzzard> wait till you're trying to find both normal and hidden files
[13:48:23] <Bytram> woo hoo!
[13:48:26] * TheMightyBuzzard grumbles
[13:48:59] <TheMightyBuzzard> need moar nicotines
[13:49:02] <Bytram> FYI I've actualy used Unix Sys V (or was it 7?)
[13:49:24] <chromas> Sys V, FF VII
[13:51:15] <Bytram> all *last* century: Sys VII, SCO, AIX, IRIX, Solaris, RedHat, as well as MKS Toolkit (on DOS, Windows, and OS/2)
[13:52:23] <Bytram> this century, mostly ports of unixutils, fileutils, etc. to Windows
[13:52:49] <Bytram> chromas++ thanks
[13:53:01] <Bytram> ??
[13:53:35] <Bytram> chromas++ thanks
[13:54:17] <chromas> I wasn't saying anything seriouth, btw
[13:54:37] <chromas> Wow, even my fingers are getting a lithp
[13:55:20] <Bytram> so why no ++ action here?
[13:55:50] <chromas> no bot
[13:56:23] <Bytram> I invite Bender
[13:56:23] <chromas> too many bots might be a decrement to the channel
[13:56:29] <chromas> unless you do it in small increments
[13:56:46] <Bytram> story queue running dry... gtg :/
[13:56:49] <chromas> Bender is speshul. I think you have to tell him to come
[13:56:52] -!- Bender [Bender!Bender@Soylent/BotArmy] has joined #qa
[13:57:01] <TheMightyBuzzard> /msg bender !join #qa
[13:57:09] <Bytram> oh....
[13:57:20] <TheMightyBuzzard> works if you is a bender admin
[13:59:38] <Bytram> ahh, don't got it.
[14:00:52] <TheMightyBuzzard> gotta add yourself to his config file in ~sylnt/.jsb on bery and restart him. i did it ages ago cause he was getting on my nerves for some reason.
[14:08:47] <Fnord666> for f in `ls` ; do echo cp -p "$f" "$f.orig";done
[14:08:53] <Fnord666> Bytram ^^
[14:10:23] <Fnord666> oh wait that doesn't handle the quoting issue yo uwere having
[14:16:52] <Bytram> yeah, I'm the King of Corner Cases
[14:16:54] <Bytram> :D
[14:18:10] * chromas gives Bytram a circle of paper
[14:18:30] <Bytram> brain is full atm; trying to parse what has already been offered today. Made excellent progress, so far. Need to chew on it and let my "background processor" iterate and let me know when it's found issues or stops squirming.
[14:21:16] <Bytram> break time; afk; biab
[14:29:22] <Fnord666> "there was a way to invoke the shell so that a copy of all inputs and outputs could be copied to a file as I went."
[14:29:34] <Fnord666> Were you looking for the 'tee' command?
[14:30:06] <Fnord666> 'tee - read from standard input and write to standard output and files'
[14:33:17] <Bytram> am familiar with tee. this, IIRC, was a way to *invoke* the shell in such a way (or maybe issue a command) that one was returned to a command prompt, could do things as I usually would, and *everything* was logged to a file.
[14:34:24] <Fnord666> Ah, ok. Not familiar with that.
[14:34:26] <Bytram> both my inputs *and* any command outputs was logged.
[14:35:06] <Bytram> it was like having everything that appeared on my screen *also* appear in a file.
[14:55:12] <chromas> man script
[14:56:41] <chromas> "script makes a typescript of everything on your terminal session. The terminal data are stored in raw form to the log file and information about timing to another (optional) structured log file. The timing log file is necessary to replay the session later by scriptreplay(1) and to store additional information about the session."
[15:53:36] <halibut> Bytram: There is a program called ``script'', which I think is pretty standard, which should do the logging of commands and results you described. Check out its man page (man script).
[15:56:30] <Bytram> halibut++ that could be it. Sure looks like it would do the trick! Unfortunately I really gtg; will play with it later. Thanks sp much!!!!!
[15:56:30] <Bender> karma - halibut: 1
[15:56:53] <halibut> Looks like chromas was on it, too.
[16:01:03] <halibut> Probably overkill, but the bash man page explains how quote removal and word splitting go. Start reading the EXPANSION section, and then when it gets to Brace Expansion, skip down to Word Splitting. It's a bit hard to get, but quotes in the output of command substitution are treated as ordinary characters, not like quoting characters.
[16:03:07] <halibut> If you save these four lines to showme.py (or something), and chmod +x showme.py, you can use showme.py in place of your echo to show what I think you want.
[16:03:16] <halibut> -------- BEGIN PASTE --------
[16:03:20] <halibut> #!/usr/bin/python
[16:03:24] <halibut> # -*- coding: utf-8 -*-
[16:03:28] <halibut> import shlex, sys
[16:03:32] <halibut> print(' '.join([shlex.quote(a) for a in sys.argv[1:]]))
[16:03:36] <halibut> -------- END PASTE --------
[16:04:18] <halibut> Example: for f in * ; do showme.py cp "$f" "${f}.orig" ; done
[16:04:43] <halibut> Kind of overkill for putting quotes back in, but I think it should work.