LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-20-2016, 11:05 AM   #16
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757

Well, I was not able to find the interval then. I think it's safer to get prompted by the mysql client for password, or maybe use a configuration file making sure its access is restricted
 
Old 11-20-2016, 03:17 PM   #17
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Original Poster
Rep: Reputation: 78
Quote:
Originally Posted by astrogeek View Post
I'm grateful for this. However, I've been reading bash-beginners-guide and it's not the smoothest introduction. It's kind of an awkward combination of vague and precise details. E.g.:
Quote:
1.3.1. General
Bash determines the type of program that is to be executed. Normal programs are system commands that exist in compiled form on your system. When such a program is executed, a new process is created because Bash makes an exact copy of itself. This child process has the same environment as its parent, only the process ID number is different. This procedure is called forking.
That seems specific and yet totally uninformative at the same time.

The main problem I'm having is understanding the script syntax. E.g., when and why do we use quote marks and what's the point of all the double parens and square brackets and what's the role of the dollar sign, and why put a semicolon after the brackets in an if statement and how do the || and && operators effect control within the script, etc.


Quote:
Originally Posted by astrogeek View Post
I also like the O'Reilly Classic Shell Scripting book as a handy print reference.
I may have to get the book. Kinda surprising that book is 560 pages!
 
Old 11-20-2016, 03:40 PM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,816

Rep: Reputation: 3071Reputation: 3071Reputation: 3071Reputation: 3071Reputation: 3071Reputation: 3071Reputation: 3071Reputation: 3071Reputation: 3071Reputation: 3071Reputation: 3071
Well I guess the general answer to question about vagueness is more of a subjective one as I find the portion you quoted completely understandable and succinct.

As for your syntax example, not only is not a single example but dozens and most of which boils down to a learning process, but to break it down a little for you:

when and why do we use quote marks :- when learning the answer is to always use double quotes unless you know why not to

what's the point of all the double parens and square brackets :- this would be a question of showing an example (which there are plenty in the pages listed), but the short list would be:

() - create a sub-shell
(()) - arithmetic operations
[] - [ itself is a bash command and is interchangeable with the 'test' command
[[]] - this is a more advanced version of the single square bracket, for example you can perform regular expressions

The above are not to be looked at as the definitive list of options either, but as said, you are to learn how and when to use each

what's the role of the dollar sign :- with a variable this is to identify you wan the variable to return its value

why put a semicolon after the brackets in an if statement :- if you read on you will find this is only needed when multiple commands are on the same line. in the case of the 'if' it will be if you place 'then' on the same line as the test

how do the || and && operators effect control within the script :- || = OR ... && = AND (at a basic level)


Again, please persist and read (re-read) constantly ... this is after all a new language you are learning
 
Old 11-21-2016, 01:19 AM   #19
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,583
Blog Entries: 11

Rep: Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602
Quote:
Originally Posted by sneakyimp View Post
I'm grateful for this. However, I've been reading bash-beginners-guide and it's not the smoothest introduction. It's kind of an awkward combination of vague and precise details.
Like grail, I think the selection you posted stands on its own well enough. Although I admit that if you have limited prior familiarity with the Unix concepts of environment and process forking, the brief mention there may not stand out.

The shell is a special kind of environment in that it puts the many powerful Unix concepts and system services literally and interactively at your fingertips.

Quote:
"Although most users think of the shell as an interactive command interpreter, it is really a programming language in which each statement runs a command. Because it must satisfy both the interactive and programming aspects of command execution, it is a strange language, shaped as much by history as by design."

- Brian W. Kernighan and Rob Pike, The UNIX Programming Environment, 1984
So some familiarity with those Unix/Linux basics will go a long way toward understanding how the shell is intended to work (and such familiarity is listed as a prerequisite in the guide).

Quote:
Originally Posted by sneakyimp View Post
That seems specific and yet totally uninformative at the same time.
That statement reminds me of a fortune, something about a helicopter pilot in Redmond... but I digress.

Try to not get bogged down, and if you can't figure something out, you know where to ask for help!

Quote:
Originally Posted by sneakyimp View Post
The main problem I'm having is understanding the script syntax. E.g., when and why do we use quote marks and what's the point of all the double parens and square brackets and what's the role of the dollar sign, and why put a semicolon after the brackets in an if statement and how do the || and && operators effect control within the script, etc.
The syntax is different from many other languages, but still it is just another syntax.

To add to what grail has already said, and anticipate a few other questions...

The [ character is actually a command, the same as test, and not just a syntax element. To see this...

Code:
$ which [
/usr/bin/[
$ which test
/usr/bin/test
One consequence of this is that you must separate the enclosing brackets from the enclosed arguments with whitespace, just as you must separate the arguments of any other command from the command itself! (Actually bash uses a built-in version of [, but the behavior is the same).

Code:
[ $# -gt 1 ] - right!
[$# -gt 1] - error!
The double square-bracket test syntax, [[...]] is an extended test notation introduced by ksh but now adopted by bash as well. It differs from the original test in that word and wildcard expansions are not performed, so quoting is less important. It also adds a list of test conditions not availale with the older test syntax, but it supports all of the older options so that you can always use [[...]], whatever test condition you are using.

Shell scripting has a few quirks, but it is well worth gaining some proficiency with it. Once you have gained basic familiarity it will become one of the most used and most powerful tools in your bag of tricks!

Quote:
Originally Posted by sneakyimp View Post
I may have to get the book. Kinda surprising that book is 560 pages!
I think it is a very good book. It is tutorial in style, but also makes a very good reference. It includes a little of the history of common shells, and their differences as well.

And unlike many computer books, it is not likely to become outdated any time soon! The shell is a well established and slowly changing component at the core of Unix/Linux, so the book will remain relevant for a long time - money well spent.

Good luck!
 
Old 11-23-2016, 02:18 PM   #20
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Original Poster
Rep: Reputation: 78
Quote:
Originally Posted by grail View Post
Well I guess the general answer to question about vagueness is more of a subjective one as I find the portion you quoted completely understandable and succinct.
Without belaboring the point too much, I have to disagree. Take this, for example:
Quote:
Bash determines the type of program that is to be executed. Normal programs are system commands that exist in compiled form on your system.
Mightn't a bash script or single line in CLI may have many commands? In what sequence are these commands executed? What is the mechanism by which BASH makes this determination (cue the PATH concept here). What constitutes "normal" and "abnormal?" Most importantly, I think this--the fourth section of chapter one-- doesn't really seem like introductory material. How about a broad overview and discussion of syntax first? Just my opinion.

Quote:
Originally Posted by grail View Post
but to break it down a little for you:
Thanks for the breakdown. Every little bit helps. So far in chapter one the only discussion of double parens or double brackets is this:
Quote:
1.2.2.4. Conditionals

Conditional expressions are used by the [[ compound command and by the test and [ built-in commands.

Expressions may be unary or binary. Unary expressions are often used to examine the status of a file. You only need one object, for instance a file, to do the operation on.

There are string operators and numeric comparison operators as well; these are binary operators, requiring two objects to do the operation on. If the FILE argument to one of the primaries is in the form /dev/fd/N, then file descriptor N is checked. If the FILE argument to one of the primaries is one of /dev/stdin, /dev/stdout or /dev/stderr, then file descriptor 0, 1 or 2 respectively is checked.

Conditionals are discussed in detail in Chapter 7.

More information about the file descriptors in Section 8.2.3.
Perhaps it is my intellectual limitations, but I think this is not especially helpful to a Beginner. The O'Reilly book looks like it will probably be more my speed.

Quote:
Originally Posted by grail View Post
Again, please persist and read (re-read) constantly ... this is after all a new language you are learning
I will overcome. I think the book is looking like a good choice. I will say that BASH seems pretty different from Javascript/PHP/Java/C/whatever.
 
Old 11-23-2016, 02:28 PM   #21
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Original Poster
Rep: Reputation: 78
Quote:
Originally Posted by astrogeek View Post
Like grail, I think the selection you posted stands on its own well enough. Although I admit that if you have limited prior familiarity with the Unix concepts of environment and process forking, the brief mention there may not stand out.
I've got some familiarity. I found the mention of forking off another process somewhat informative and also odd. Why mention process forking before we cover the basics of syntax? Does the primary process go to sleep? Couldn't it just execute the script itself? At what point is the other process forked? Is the script parsed in its entirety first or one line at a time? Does the parent process parse the file or does the child process parse the file?

Quote:
Originally Posted by astrogeek View Post
That statement reminds me of a fortune, something about a helicopter pilot in Redmond... but I digress.
???

Quote:
Originally Posted by astrogeek View Post
Code:
$ which [
/usr/bin/[
$ which test
/usr/bin/test
Whoa. Interesting.

Quote:
Originally Posted by astrogeek View Post
One consequence of this is that you must separate the enclosing brackets from the enclosed arguments with whitespace, just as you must separate the arguments of any other command from the command itself! (Actually bash uses a built-in version of [, but the behavior is the same).
This extra space requirement was a source of great confusion. Thank you for laying it bare.

Quote:
Originally Posted by astrogeek View Post
I think it is a very good book. It is tutorial in style, but also makes a very good reference. It includes a little of the history of common shells, and their differences as well.
Yeah the book looks readable.

Quote:
Originally Posted by astrogeek View Post
Good luck!
Thank you!
 
  


Reply


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
LXer: Bash script to Redis SCAN e.g. for pruning, migration and archiving LXer Syndicated Linux News 0 11-08-2015 07:20 AM
How do I perform commands in a bash script as a different user? theonislair Programming 5 06-10-2012 01:10 PM
[SOLVED] Failed miserably to execute bash script via PATH variable after FS migration. kopatops Linux - Software 21 08-18-2010 06:34 AM
script Q : how do I force bash to perform the math? kevinyeandel Linux - Newbie 4 02-20-2009 02:35 AM
helping me in a bash script that perform a "select" menus Task adam_blackice Programming 5 09-15-2007 01:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:24 PM.

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