« first day (1180 days earlier)      last day (3768 days later) » 

12:51 AM
@derobert angry Linus wanted you to know: he's on your side. casibien.files.wordpress.com/2012/10/22814678.jpg
 
slm
1:01 AM
@strugee - I love that angry linus
 
especially relevant since you just upgraded
 
0
A: Count the number of characters in all files

GillesHere's a way to do this in a single shell command. <foo awk 'FILENAME=$0{while(getline<FILENAME>OUTPUT&&match($0,"$"))RSTOP-=RSTART}END{print-RSTOP}' This may not be the least awkward way to do it. Be sure to tell me what your teacher thinks of it.

 
slm
@Gilles - now you're doing ppl's homework 8-)
 
heh. "may not be the least awkward"
although you did forget to assign it to $count
 
@strugee ah, dammit
do you think it counts if I assign it in awk?
 
1:15 AM
probably
 
there, done
unfortunately, the way I did it may make him think it didn't work
but I do assign it to the shell variable count, and it does work if you run it right
 
@slm Odd, why did no one vote to close?
 
slm
0
A: Count the number of characters in all files

slmSince apparently we're answering this quesiton now. Sample data $ ls -1 afile1 afile2 afile3 filelist.txt $ cat afile{1..3} blah blah blah Example $ cnt=0; for i in $(< filelist.txt);do \ let cnt="cnt+$(wc -c $i | cut -d" " -f1)";done; echo $cnt 15 In it's expanded form: $ cnt=0; $ fo...

I did one too
 
@slm you failed, that's not a single statement
 
I wonder why he tagged it cat. reminds me of the useless uses of cat award
 
1:29 AM
Yeah. Maybe that's the list of Unix commands OP knows?
 
pipe isn't a command
otherwise I would agree with you
 
I bet the actual assignment was to read man wc and see --files0-from=F ...
If you all want to do someone's homework, there is a sorting one on codegolf!
236
Q: I need a program where the user inputs an array of doubles and the program outputs the array sorted

VictorNote: This question was severely edited since I first posted it here. The rules were moved to here, read them before posting any answer to understand the purpose of this. This was the first question created in the code-trolling category. Imagine a lazy user on Stack Overflow asks this question: ...

 
I've never actually bothered to read any of man wc except for the top where it specifies the -l, -c and -w switches...
 
slm
@derobert - what constitutes a statement? It's on one line, that's a statement in my book
 
@slm I would agree but yours wasn't on one line. I mean, it could easily be put on one line, but I think @derobert was nitpicking
 
1:40 AM
@slm Nah, semicolons separate statements (most of the time). A statement is a formal part of a language's grammar... yes, this is very nitpicky.
 
do people see a need for a shell-startup tag? I'm asking a question that might use it right now, but I'm not sure if it's useful
 
I'm not sure what you'd use it for...
 
slm
I split it on one line for readability on the site. I hate when code shows up and I have to scroll over to the right
Wow skeet is up to 635k
4
Q: Why does the wc utility generate multiple lines with "total"?

HyperQuantumI am using the wc utility in a shell script that I run from Cygwin, and I noticed that there is more than one line with "total" in its output. The following function is used to count the number of lines in my source files: count_curdir_src() { find . '(' -name '*.vb' -o -name '*.cs' ')' \ ...

 
@derobert e.g. .bash_profile, .profile, .zshrc, etc.
 
@strugee Is there an expert in that? Probably not. There is an expert in bash (and zsh, and ksh, and even csh), surely, but in shell-startup? I don't know...
 
1:43 AM
/me shrugs
that's why I asked, since it seems like it might not be used very much
 
I wouldn't bother :-P
 
ok.
switching topics, just out of curiosity, has anyone here ever played with Plan 9? (mostly asking since I'm setting up a space for a Plan 9 server right now)
 
not I
 
@derobert or a command substitution, which is the way I'd do it
I posted that question and a variant of the answer in the place where it belongs:
0
Q: Count the total number of characters from a list of files

GillesThe challenge: A file foo contains a list of filenames. Devise a single statement that stores in a variable count the total character count of the contents of these files. (From crisron's teacher via http://unix.stackexchange.com/questions/107336/count-the-number-of-characters-in-all-files...

 
Now I'm tempted to answer it!
I'm not sure though, it's possible a good answer would require FUSE. Or maybe direct access to the underlying filesystem.
For efficiency, of course.
 
1:49 AM
so am I, with a solution involving curl, make, gcc and friends
 
@slm I left a confusing comment on your answer. <evil laughter>
 
curl? This should be interesting!
Actually. Hmm. I know!
EVIL GRIN
 
@derobert yeah... it's not all that clever once you figure it out
 
@strugee no, I'm referring to what I just thought of. I need to grab a name dictionary, first...
 
ah
I think I spend to much time at the terminal/on Stack Exchange, because I just opened an instruction sheet to assemble a table for a P9 server
and it said "assembly instructions" at the bottom of the front page and my mind immediately went to x86 assembly
 
slm
2:01 AM
@derobert - here's your --files0-from method
1
A: Count the number of characters in all files

slmSince apparently we're answering this quesiton now. Sample data $ ls -1 afile1 afile2 afile3 filelist.txt $ cat afile{1..3} blah blah blah Example $ cnt=0; for i in $(< filelist.txt);do \ let cnt="cnt+$(wc -c $i | cut -d' ' -f1)";done; echo $cnt 15 In it's expanded form: $ cnt=0; $ fo...

@Gilles - I fixed the stray quote, i had double quotes from a cut nested inside the let's double quotes
 
Working on my trolling answer.
 
@derobert you taking my lines (that I took from someone else)?
 
@slm oh, there really was a stray quote? I hadn't noticed it!
 
I shall nest map repeatedly!
 
slm
@Gilles - I have to agree these are actually not bad Q's for us to have on the site, but I feel we're sending the wrong msg by helping these ppl
 
2:05 AM
the “stray quote” I meant was an it's that should have been its
@slm if he submits my answer without trying to understand it, he's going to get a lesson on doing his own homework
if he works to understand my answer, he's going to learn a lot about awk
 
slm
@Gilles - i see the quote now, fixed.
i'm not sure if you can have nested quotes inside of a let
the code worked before
 
@slm you can
 
slm
ah so it was legal then, I changed it to single quotes any way for cut
 
rather: the quote was inside a $(…), and you can use quotes normally inside $(…)
@slm yes, but it worked either way
 
slm
ah yes you'd be correct completely missed i was inside the $()
 
2:16 AM
@slm you aren't assigning to count
can you throw something in so that it works if the variable is called cnt, but not if it's called count?
use count as the loop variable, for example
 
slm
2:33 AM
@Gilles in the golf example or on U&L?
 
@slm at least in the PCG example, where the point is to make the code work (at least on some input) but be brittle or unmaintainable in some way
your code is almost decent
 
slm
@Gilles - do you just want me to change the $i to $count in the loop?
I've never seen the code-trolling tag before
 
@slm it's new
 
slm
so just change the index?
i'm drawing a blank on how you want me to make it brittle
 
				local $p = $p; # this line is important! do not delete.
... random line from my answer, still in progress :-P
 
slm
2:38 AM
oh just change the scope of $cnt?
 
@slm change the loop variable, so if he just renames cnt to count he'll have a clash
or whatever you want to make it a more brittle
@slm you forgot to change one occurrence, it only works for a single file. Or was that deliberate? (Answers that work for sample data but not in general are allowed, even somewhat encouraged)
 
slm
that was intentional
that was how i was obfuscating the original answer over here
i still don't understand what you want me to change
it's unantural to make it terse
cnt=0; for i in $(< filelist.txt);do let count="count+$(wc -c $i | cut -d' ' -f1)";done;
 
i think he wants you to change i's name
 
slm
i changed cnt to count, i thought there was more to it though
Also why did someone dv your Q there?
someone commented about my code not being very trolling, i think i'm missing the point of something here, i read the code-trolling tag
 
@slm I'm new to that tag as well, maybe we're missing some convention
did you read the tag wiki?
you should probably explain more what the trolling aspect is
 
slm
2:55 AM
@Gilles - I made the variables more brittle as you suggested, so now it sometimes works and doesn't display the value, I also neutered the --files0-from example so that you have to know ho to extract the value using awk etc. yourself
@Gilles - this site seems like it's gonna have a hard time getting out of beta
 
@slm yes, I wouldn't be surprised if it remained in beta indefinitely
I have a close vote on the question because I didn't provide an objective winning criterion
I guess it'll be score by default (that's allowed)
 
0
A: Count the total number of characters from a list of files

derobertI believe the below Perl solution fits the requirements. In order to use it, you'll need to prepare several data files: first-names: should contain a list of possible first names, separated by newlines. last-names: same, but for last names. titles: a list of titles (Mr., Mrs., Lord, etc.). Mak...

 
slm
ah
 
There, my answer!
 
slm
@derobert - took you long enough 8-)
 
3:00 AM
take a look at it, and I think you'll understand why...
 
slm
wow you really did it with map, i thought you were joking
 
LOL at “characters”!
 
who needs loops, when you have map? :-P
@Gilles yeah, that was my EVIL GRIN when I realized I could use that meaning.
I wonder how big the first-names, last-names, and titles files can be, before the regex compiler dies
 
slm
@deroberts - i can't believe you made this abomination
 
did you try it on real input, like a Shakespeare play?
 
3:04 AM
@Gilles hell no!
anthony@Watt:/tmp/cc$ cat f1
Hello, John Smith!

Welcome to Washington.

Smith, John left.
anthony@Watt:/tmp/cc$ cat f2
Lord Bob Smith ate a cat. Mr. Smith was full.
@Gilles next you'll want me to try it with a real list of first & last names. I wonder if I have enough RAM...
 
3:34 AM
I've made some improvements, I'm tempted to combine the sum into the counting code (in the obvious way). That'll still be one statement, I think. Or it could be, as I could not use block map there.
But then of course it'd lose the joke about "the statement you're looking for" being a trivial and obvious one
 
 
14 hours later…
5:59 PM
Anybody home? I need some help with SSH master connection
 
6:13 PM
@davidkennedy85 don't ask to ask, go ahead and ask
 
Okay
Well I'm trying to do this from an expect script
So the first thing I do is spawn ssh -N -M root@192.168.1.1
Then I have my expect {} block to send the password
But at that point I'm kinda confused about what to do next
For instance, the next command that I run will run on the remote server or local?
And if it's local do I need to spawn scp or just scp?
 
as long as you're interacting with the ssh command (with send), you're executing remote commands
if you run other commands with spawn, they're local commands
 
So in an expect script I can never run just straight up scp command?
It always has to be prefixed with either spawn or send
 
you can use any tcl command
expect is a tcl library (well, extension)
 
Ono I don't know what tcl is :(
 
6:18 PM
Tcl (originally from Tool Command Language, but conventionally spelled "Tcl" rather than "TCL"; pronounced as "" or "tee-see-ell") is a scripting language created by John Ousterhout. Originally "born out of frustration", according to the author, with programmers devising their own languages intended to be embedded into applications, Tcl gained acceptance on its own. It is commonly used for rapid prototyping, scripted applications, GUIs and testing. Tcl is used on embedded systems platforms, both in its full form and in several other small-footprint versions. The combination of Tcl and ...
 
In general normal bash commands are not tcl commands though right?
 
If you don't want to learn tcl, write your program in another language and only use expect to launch the ssh master connection and send the password
@davidkennedy85 no, they are different programming languages
 
By write it in another language, you mean call a bash script from my expect script?
 
no, the other way round
 
ah
That sounds like a good approach
Thanks for your tips I will probably be back in a bit
 
slm
6:40 PM
@terdon - I thought this was a novel way to use paste
0
A: how to cut and transpose some line of the file in linux?

slmOnly because I love using paste so much, you can actually do this with paste, though it isn't pretty: Sample data $ seq 100 > data.txt Example $ paste -d " " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - < data.txt 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

The 2nd example is actually smaller than your perl example 8-)
 
@slm hah, I just upvoted that, it was a great paste!
Especially with the loop, very nice!
Happy new year by the way
 
slm
see the xargs example i just added too
same to you bud
 
7:00 PM
I'm using getopts to set a bunch of variables in my script: $source, $dest, etc.
Is this a good way to check for missing arguments?
${source:?"source not specified"}
${dest:?"dest not specified"} etc.
 
slm
tcl is a pretty retried programming lang. I've used it extensively for years
 
I mean in bash
I know I can do if [ -z $source ] but the ${param:word} syntax is a little neater, just not sure if I'm doing it right
Nvm I think I probably want to if [ -n $source ] as it checks for empty string
or if [ ! -n $source ] rather
 
7:29 PM
@Gilles would you put the initial ssh connection in the bash script or the expect script?
 
@davidkennedy85 expect, it's the whole reason to use expect at all
 
Sorry I'm having trouble with the workflow
So my bash script calls expect like this: expect -f upload.exp $params
then upload.exp does ssh whatever; expect {}
What was the point of doing the bash script again?
Are all the ssh commands from that point going in bash script or expect script?
I was under the impression the expect script would do only the part that I can't do in bash
 
expect to start the master ssh connection
shell to do everything else
including killing the master connection at the end
 
Wouldn't putting ssh -O exit at the end of the expect script cause the connection to terminate before the rest of the ssh commands in the bash script?
Oh wait
Sorry I read that the wrong way, ssh -O exit goes in bash script
This is like one of the most complicated programs I've ever made
 
7:50 PM
0
Q: bash script calls expect script with master SSH connection madness

davidkennedy85I'm trying to write bash script that calls an expect script to establish a master SSH connection to be used for the remaining SSH commands in the bash script. I'm a little worried about running it though because it is really confusing and I'm not sure if I'm doing it right. ~/.ssh/config: Contr...

 
8:11 PM
@Gilles could I bother you to glance at that Q?
I just want to make sure I'm understanding this
 
 
2 hours later…
10:13 PM
Can someone please take a look at that question? I'm stuck trying to figure out why the SSH connection can't authenticate from my script
 

« first day (1180 days earlier)      last day (3768 days later) »