Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-15-2013, 08:26 PM   #16
Senior Member
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235

Originally Posted by w1k0 View Post
if [ 2 -gt 1 ] && ( [ 1 -gt 0 ] || [ 1 -lt 0 ] )
    echo "Well done w1k0"
Unfortunately you'll have to summon yet another unnecessary subshell for that which terribly slows down the process. Still not possible with the current shell only and is already more like an encapsulation trick which always has been an obvious hack to me.

Now you might find optimizations in some implementations, but '()' is meant to cause a subshell environment.
Originally Posted by w1k0 View Post
echo "Hello"
echo "Hello `echo k0`"
echo "Hello `echo w1\`echo k0\``"
Good luck trying to quote that with every level. I still don't see that as truly recursive. It's so much like eval.
echo "`echo A\`echo B\\\`echo C\\\\\\\`echo D\\\\\\\`\\\`\``"

Last edited by konsolebox; 04-15-2013 at 09:00 PM.
Old 04-15-2013, 09:13 PM   #17
Senior Member
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Oh yes you could have used a cleaner way:
true && { true || { true || false; }; }
Though that doesn't really look like a sequence of conditional statements anymore and is clearly compound statements playing around with exit codes. Way too far already compared to the better solution [[ ]].

And yet again don't forget that those can't entertain expressions. Perhaps you would make use of "case" for that? But how would you group that with other conditions?
Old 04-18-2013, 01:31 PM   #18
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
(Apologies in advance for the long, off-topic post.)

Originally Posted by w1k0 View Post
David the H.,

I see the similar post written by you for the sixth time during last two weeks. It seems that you have a mission from God to popularize the right methods of quoting and formatting the posts. jason13131414 published here 9 posts so far. It takes some time before a newbie grasps all the rules. Would you like to educate each newbie here? Put a short tutorial into the signature of your posts. Do not post the same content for the dozens of the times because it is boring. Each day a bunch of newbies join Maybe you should write a short tutorial, send it to jeremy, and ask him to post it to the every new LQ member? It seems reasonable solution.
Well, I wouldn't call it a mission "from God", since I'm an atheist. But yes, I do tend to focus a lot on correcting the errors I perceive. Perhaps too much. I'm also quite aware that it's repetitive. If you think it's tiring reading it for the sixth time, try writing it for the fiftieth. (Yes, I do C&P a lot of pre-written sniplets too, but I also try to personalize them when I feel it's appropriate.)

But I don't see much of a way around it, other than to give up posting. As you said, there are always newbies coming through, and the same errors keep popping up again and again. They need to be addressed when and where they are encountered.

I reject the tutorial idea because: a) I doubt Jeremy would agree to spamming everyone with it, particularly since not everybody comes here to learn scripting. At best it would go into the LQ tutoral section where few newbies would notice it. b) Very few would bother read it anyway, or be able to recognize what was important about it, until it became personally important to them, and that comes from the discussions offered when they post. c) There are better tutorials like the BashGuide already out there. So I guess I'm stuck with pointing out errors and giving links to deeper explanations.

And no, I don't expect that newbies will pick it all up right away, or that everyone has to follow my advice to the letter. I just post my suggestions and examples in the hopes that they will learn something new. Everybody has to learn at their own pace, all I can do is try to help them along.

On the other hand there are a lot of the ways of the formatting the posts which are acceptable. I – for example – put the content of the files (data files and scripts) into the code section and I use bold font to mark the files and directories names as well as the separate commands (the commands which are not the part of the scripts). It is not reasonable to expect that in the forum used by the thousands of the users each of them will use exactly the same style of the formatting of the posts.
In every community there are community standards, and if you want to be an accepted member of that community you need to, at least broadly, follow it. This is just how society in general works. Nobody expects you to be perfect, but you should at least try to stay consistent with what others are doing. Newbies get more slack, of course, but they also get corrected on their "mistakes" so that they will learn how to fit in better.

In any case, the only real demands that I know of here are that any pre-formatted data and code be enclosed in code tags, that you don't post homework or expect others to do everything for you, and that you do your best to explain exactly what you want to accomplish and post the data and commands you're trying to use. In other words, we expect you to work with us in the spirit of cooperation and problem-solving, and not just treat this as a free help desk.

As for the bash techniques the most important is the difference between the working and not working ones. The backticks and the single brackets work so they are valid ones. Using or avoiding them is a matter of the style of the coding. You – and the other people – can call some coding styles better than the other ones but it is only a matter of the taste. So it is not reasonable to expect that each coder will share your taste.
If there's one thing I've noticed as I've gained experience, it's how my coding practice has drifted closer and closer to that of the experienced users who have advised me in the past (both personally and through online guides). I was once like you and thought that a lot of these things were mostly just a matter of "personal taste", but I have since realized that the gurus don't just suggest these things on a whim, they are speaking to you as people who have already suffered the pain of experience, and are trying to help you avoid going through the same difficulties.

Certainly there are some things that are mostly a matter of style. A lot of these are formatting questions; how much to indent, whether to put the "do" keyword on the same line as "for" or on a separate line, and so on. But advice about syntax, like quoting, brackets, and backticks, are not of that kind. There are good, practical reasons for them, and if you continue coding for long enough, you'll likely come to realize it for yourself, like I did, and understand that what once seemed like pointless criticism was really valuable advice.

By the way, I'm not sure if you've noticed it yet, but one thing I always endeavor to do is to back up what I say with documentation and links to recognized scripting guides. And if it is just my opinion or a "personal style" thing, I try to clearly state that too.

As a final point, I obviously can't dictate what you will do personally. In the end they're your scripts. But do be aware that if you post suggestions to others that include syntax that has weaknesses, or for which there are better options, I will work to correct them. It's one thing to use poor code yourself, but I won't just stand by and watch it being taught to others.

Last edited by David the H.; 04-18-2013 at 01:34 PM. Reason: typos
1 members found this post helpful.
Old 04-18-2013, 04:58 PM   #19
Senior Member
Registered: May 2008
Location: Poland
Distribution: Slackware, Mint
Posts: 1,252

Rep: Reputation: 205Reputation: 205Reputation: 205
David the H.,

Thank you for the extended reply. In your post #10 you discussed with Jman-NZ from the post #8 – not with me from the post #7.

Last edited by w1k0; 04-18-2013 at 05:01 PM. Reason: removing doubled content


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash-script] A question about using grep in the script thomas2004ch Linux - Software 2 03-05-2012 04:27 AM
Bash script question stillme Programming 15 05-09-2010 10:56 AM
Bash script question.... mkhan919 Linux - Newbie 3 04-06-2007 07:13 AM
Bash script question J_Szucs Linux - General 4 05-29-2003 09:48 AM
A bash script question J_Szucs Programming 2 05-13-2003 03:13 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration