« first day (2578 days earlier)      last day (2375 days later) » 

2:22 PM
Is there a nice way to loop from argument $3 till everything there is?
Right now I am using for ((i = 3; .....
I suspect that there could be something like for arg in $@ sort of way out
 
3:00 PM
@Yashas What shell are you using? Is it bash? (I'm just guessing from the C-style for loop syntax that not all shells support.)
 
bash
I actually solved it
just realized that I could have done ${@:3}
 
With ${!i} ?
Oh, by slicing the array. Ok.
 
is there a simple way to achieve this:
input is "3 4 2"
I need to create "3,3 4,4 2,2"
as of now I am using tr to replace spaces with newlines then piping it to awk
and printing each line twice with a comma
 
Well I'm not sure what you're using it for so I'm not sure what the best way to do it is. But substituting with sed comes to mind:
sed -r 's/([^ ]+)/\1,\1/g'
[^ ] is a character class that matches any single character other than a space. Putting + after it matches one or more non-spaces. Enclosing that in parentheses makes it a capture group. The group's opening parentheses is the first that appears in the pattern (in this case it is the only one) so it can be accessed as \1.
Passing the -r flag makes sed use extended regular expressions; I did that just so I wouldn't have to write + as \+. s tells sed to match a regular expression and perform a substitution. I chose /as my delimiter, as is common. The regular expression ([^ ]+) is matched, and in place of each matching string, \1,\1 is outputted, with each \1 replaced with what the parenthesized expression matched.
The g at the end causes it to do this as many times on each line as there are matches, rather than at most once per line.
Since you're actually replacing entire matches, you can actually forgo the explicit capture group altogether and just use the \0 group which is the entire regex match:
sed -r 's/[^ ]+/\0,\0/g'
Anyway, regarding the first problem, if you find that you do need to access positional parameters by number where the number is itself stored in a variable, you can do that by performing indirection with !, which bash permits in parameter expansion. The ith positional parameter is accessible as:
"${!i}"
For example, I made a script called from3:
#!/bin/bash

for ((i=3; i<=$#; ++i)); do
    printf 'Argument %d is "%s".\n' "$i" "${!i}"
done
$ ./from3 first second third fourth fifth
Argument 3 is "third".
Argument 4 is "fourth".
Argument 5 is "fifth".
 
3:31 PM
@αғsнιη I don't see any change there, only clarification. But my main point is that if you do take the time to improve a post (thanks!) and add a tag, please also remove any wrong tags. None of the tags there were actually relevant to the question. And just be careful when adding text, be sure it is correct. I know this isn't easy, and I'm cheating since English is my language, and it really is no big deal, but just you know, be careful :)
And I have no idea why I had commented twice there! Server glitch? Well, terdon glitch, or server glitch. Something screwed up anyway :)
 
4:15 PM
@terdon English is your language? I would have guessed Greek...
 
@derobert Both. And my English is considerably better than my Greek. I was raised bilingual (Dad's American, Mom's Greek) but the last 2 years of highschool were in English, as were all of my subsequent academic studies, as well as work. And I read in English much, much more often than in Greek.
Well, I guess not 'considerably better'. I speak Greek like a native speaker. I speak English like a native speaker with a university degree, a book addiction and language geek leanings.
2
I'll mix them up, mind you, but that's the price of being multilingual.
 
Hah
 
If I have to choose one language in which to express myself, that would be English. Ideally though, I like to be able to pick and choose :P
 
Just watch out when you mix them up, English has a tendency to steal everyone else's words :-/
 
Oh yeah, that it does.
 
4:21 PM
Then of course mangle them beyond recognition.
 
English and Greek I can keep separate easily enough since I was raised speaking both natively. It's the ones I picked up as an adult that tend to bleed into each other and the mother tongues.
For instance, when I first started learning Spanish, I lost my French. Then, when I moved to France, I got my French back but at the detriment of my Spanish for a few months. After a while, they were all sorted again, but there were some confusing times there :)
 
I can sort of imagine, never experienced that myself — being monolingual. Well, except computer languages, but those don't count.
 
@derobert Why, by the way? Because you know I'm Greek or because I've come across as a non-native speaker here?
 
@terdon Because I know you're Greek.
Or at least, are currently in Greece.
 
@derobert They kinda do, actually. When starting a new language, you keep using the idioms from the one(s) you knew. Then, as you get more immersed in the new one, that one now creeps into what you write with the original ones. You need to reach a minimum level of proficiency in the new one as well and then they sort themselves out. At least, that happened to me with Perl and Python.
@derobert Ah, phew. That would have been embarrassing :)
 
4:27 PM
@terdon Yeah, that definitely happens. But I say they don't really count because it takes, what, half a year to be nearly fully proficient in a computer language? A lot less work than a human language.
 
True dat.
Unless it's C++, apparently. Then it takes years.
 
Hah, that is a complicated one. I used to do C++. Learning Java after having mastered C++ was ... errr... an exercise mainly in profanity. Just had to keep reminding myself, but it has garbage collection! which lets you forgive a lot of language flaws.
 
I've poked C a bit. C++ I wouldn't poke with a ten foot pointer.
 
@derobert I don't think "modern" C++ and Java resemble each other so much. I suppose the syntax is similar.
@terdon That's sensible.
 
C++ is definitely complicated. A lot of times needlessly so. Unfortunately a lot of times because the standard committee seems to have run out of time, and just shipped whatever they had when it was time to hit the pub...
 
4:32 PM
@terdon I don't think that's actually possible. Also, the language is changing.
 
@FaheemMitha No, but this was a while ago. Early 2000s.
 
@derobert Yes, maybe they were more similar once.
C++ seems to get more and more complicated, with more and more "subtle" features.
 
Well, they were a little similar.
 
I haven't used it for a while, and no doubt if I did, there would be a half dozen new things to learn.
 
@FaheemMitha Yeah. Some of those "subtle" features are just WTFs. A lot of them, though, are useful and, once you get used to them, you really miss them in other C-like languages.
 
4:34 PM
Stroustup wrote in an introduction to one of his books that he enjoyed using C++ more than ever. Well, some people enjoy wearing a hair shirt.
@derobert C++ is definitely powerful if you want those kind of features in that kind of language.
But running screaming in the opposite direction is also an option.
 
I have no idea how nice/terrible C++17 is. Someday maybe I'll work with it again. There are a lot more options for low level languages nowadays, e.g., Rust.
 
@FaheemMitha An option? I thought it was a compile-time flag.
 
I used it for a while, from around 2001 to around 2013 or so. And this was only borne on me gradually.
@terdon :-)
 
@terdon -fno-run-screaming?
 
Or something, yes :)
 
4:36 PM
Still it was an educational experience. Learning C++, I mean.
Taught me how much complexity some programmers are willing to tolerate. In exhange for much moolah, no doubt.
 
Gotta make sure when running away screaming that you stay within the bounds of the street — otherwise, undefined behavior.
 
There's an element of Stockholm Syndrome there, I think.
 
Complexity can also be fun. Unfortunately.
 
@derobert Yes, C++17 seems to have quite a lot of new stuff. Though that fancy thing they've been waiting for isn't there yet.
Now what's it called?
@derobert People who like complicated can do Math. Number theory is complicated enough to satisfy anybody.
And at least the complexity is "natural", not a human invention.
And not just number theory. Much of mainstream math is increasingly complex.
 
@FaheemMitha Well, remember a lot of programmers are compsci folks. So probably do enjoy math. But harder to get paid for doing abstract math.
 
4:40 PM
@derobert Mainstream "pure" math is very different from Computer Science.
And anyway, I know nothing about Computer Science.
I just know it's very different.
 
Sure. Math has a bunch of branches, a lot of them are pretty different from each other.
 
Number theory is just an example of something that is very complicated. Also algebraic geometry, and a lot of other branches. Some of which don't have proper names, and many of them have connections to each other.
But it's very different from a complicated language like C++.
Research math is quite big these days. And very scary for outsiders. Though practitioners seem to cope.
(Anyway, I ramble.)
Actually, I'd say programming languages and programming in general don't approach the kind of difficulty that math has. At least in programming you have a map and directions.
In math you're basically lost in a trackless jungle, without a compass.
 
4:56 PM
@FaheemMitha Well one (maths) is research while the other (programming) is application. In research you try to break new ground, in programming (or engineering in general) you're trying to apply already known things to solve issues. Not a waterproof distinction, obviously.
 
@Kusalananda Yes, they are in different areas.
 
Hi, btw...
 
Hi.
Well, areas of human activity, that is to say.
@terdon I don't think that's ever happened to me. Of course, I don't know many languages. But I have spent time chafing over restrictions. Why can't I do this in this way, dammit?
C++ is particularly terrible in that respect. It's like wearing a steel corset or something.
@derobert Terdon speaks English like an educated native. It's hard for people to do that in multiple languages, other than professional linguists.
Though I've got a feeling that Gilles, for example, is equally articulate in both English and French. And possibly other languages.
I'm basically monolingual myself.
Combination of accident of birth and laziness/apathy.
Though the English of the Swedish people here is also very good.
Meaning Anna and Kusalananda. And I'm assuming English is not their native tongue.
 
@FaheemMitha It's not.
 
And I've been in contact with a fair number of Germans who wrote excellent English. Better than most native speakers.
David Kastrup, for example.
@Kusalananda That's what I thought.
Actually, most Free Software people (I suppose the going term is "hacker") write at least serviceable English. Often it's good to very good. But I suppose most of them are highly educated and read a lot.
 
5:10 PM
@FaheemMitha In my experience (of having worked in New Zealand and in the UK), the worst spellers are the natives. I think it has to do with learning the language as a 2nd language; you know the rules better, or rather, you don't improvise spelling and grammar as much.
 
@Kusalananda Possibly. Though I'd really have to count myself as a native speaker. Then again, my spelling is not great.
Though at least according to US universities, it's impossible for an Indian to be an English native speaker.
 
@FaheemMitha Well, I know for a fact that I have Swedish friends that have English as their first language, and other Swedish friends that have Farsi as their first language. Nationality does not dictate what the first language is.
 
And I've certainly not been impressed with native English speakers in general. Though educated UK speakers don't do badly in general.
@Kusalananda I guess some university bureaucrats didn't get the memo.
Knowing a language really well is difficult, unless you have a gift for it. Languages are complicated things.
Reading a lot helps, I think.
It also helps if you care about being correct. Lots of people don't.
 

« first day (2578 days earlier)      last day (2375 days later) »