LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can someone explain `...' syntax to me? (https://www.linuxquestions.org/questions/linux-newbie-8/can-someone-explain-%60-syntax-to-me-4175463255/)

mark_boyer 05-23-2013 11:39 PM

Can someone explain `...' syntax to me?
 
I've read some things where there is a quoting style like `expression'. The opening quote is the one below the ~ and the closing quote is the one below ". Can someone please give me a term for this and tell me how it works please?

chrism01 05-23-2013 11:46 PM

Please show a complete example/quote or give a link; its a bit tricky without seeing it ... ;)

Shadow_7 05-23-2013 11:47 PM

As a forum writing style? Or as a code element?

`` means to execute the contents between the ``
'' means to not interpret the contents between, so $VARAIBLE is literally the resulting string of characters and not the value of $VARIABLE
"" means to interpret so $VARIABLE would be the contents of the variable.
At least as far as bash syntax goes.

And then there's .. which is the parent directory and . which is the current directory. And other things.

mark_boyer 05-23-2013 11:58 PM

Maybe just man page style
 
It's hard to search for punctuation and I don't off hand remember where I saw it. I was thinking it is bash. Maybe it's just the style of man pages.

Here is an excerpt from the AT&T unix grep man page.

The apostrophes ensure the entire expression is evaluated by grep instead
of by the user's shell. The caret `^' matches the null string at the
beginning of a line, and the `\' escapes the `.', which would otherwise
match any character.

To find all lines in a file which do not contain the words `foo' or
`bar':

$ grep -v -e 'foo' -e 'bar' myfile

A simple example of an extended regular expression:

$ egrep '19|20|25' calendar

Peruses the file `calendar' looking for either 19, 20, or 25.


I notice the command line parts use vertical quotes.

chrism01 05-24-2013 12:13 AM

In that case, I assume you're asking about single quotes, not ellipsis (ie ... ) .

Basically, if you enclose a value in double-quotes (" above the 2 key), the shell can process (aka interpolate) that value and replace anything that looks like a varname with the corresponding value; ditto wild card chars like '*'.

If you use single quotes ( ' below the @ symbol on my UK keybd), this protects it from the shell & passes it unchanged to the calling prog eg grep.

If you use back-quotes ( ` on top left key of my keybd) around a string like `blah`, the shell interprets that as a cmd to be run.
NB: backquotes are deprecated; use $(blah) instead.

Read these links for the full info; you really need to grasp this as it'll save you endless stress ;)
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/

HTH

mark_boyer 05-24-2013 12:27 AM

I was asking about ` opening and ' closing, so that they are not properly matched. After looking through some man pages I had seen recently and my browser history, it seems that this was for a human reader, not the shell. Thank you, though.

shivaa 05-24-2013 12:45 AM

Just follow these tutorials:

http://mywiki.wooledge.org/Quotes
http://tldp.org/LDP/abs/html/quoting.html
http://tldp.org/LDP/abs/html/quotingvar.html
http://www.tldp.org/LDP/abs/html/index.html

chrism01 05-24-2013 01:26 AM

@OP: yeah, got to be careful there. Note also that you can't always copy quotes from eg a word processor (think they're sometimes called 'magic quotes'); they end up as ctrl chars iirc... :)

David the H. 05-24-2013 12:19 PM

In documentation, like man pages, you'll often see ``..'' used as quotation marks. Single versions of the quotes will sometimes be seen too, as the above example shows. These will never be part of any actual code; it's just an old, traditional style of formatting that originated way back the early days of computing.

All shell syntax, at least in the bourne-based shells, will always only use paired symbols (ascii quotes, brackets, parens), sometimes with a prefixing character as well, such as with the $'..' ansi-c quoting pattern.

I can't rule out the possibility of an occasional oddball program that has its own crazy syntax using something like that, however.


PS: While we're on the subject, remember that $(..) is highly recommended over `..`. ;)

Diantre 05-24-2013 02:35 PM

Quote:

Originally Posted by mark_boyer (Post 4957760)
I've read some things where there is a quoting style like `expression'. The opening quote is the one below the ~ and the closing quote is the one below ". Can someone please give me a term for this and tell me how it works please?

There's some information in these pages:

http://unix.stackexchange.com/questi...-double-quotes

http://en.wikipedia.org/wiki/Grave_a...in_programming

jpollard 05-24-2013 04:21 PM

It actually depends on where you are reading.

Old man pages (I mean REALLY old, like 1980 vintage), the man pages were designed to be typeset and printed into a reference manual.

The original formatting was defined by "troff", short for "typesetting roff" where "roff" was the original runoff application. troff developed several input styles (tbl for tables, eqn for equations, pic for pictures, toc for table of contents generation, and one for cross reference indexes). These were used by Bell Labs for their document preparation, some of the lost utilities included "style" which would validate documentation as matching the lab standard. These and others were provided in a toolkit called "The Documenters Workbench". Most of auxilary tools disappeared, and the troff utility expanded by having multiple output formats added/generated.

groff which is an extended form of troff can do postscript/pdf - see the manpage for the added utilities available :).

One early post formatting tool was "nroff" (for "not troff"). The correct formatting for quotes is to have a left quote (now called the "grave" - http://www.cs.sfu.ca/~ggbaker/reference/characters/), and a right quote (a mirror image). nroff, because it was formatting for a terminal/basic printer, used ascii, which did not have the full quoting - so it substituted an apostrophe (') for the closing typesetting quote (the mirror image of a grave). Thus the odd appearance in some documentation.

What made it worse was adding the backtic and apostrophe for shell programming. In troff these are drastically different characters than used for quoting, and usage is plain. In nroff, they are not clear, and it gets confusing when the formatting uses plain ascii.

ON to the next confusing part...

The original man utility itself, was just a short shell script - basically just one line, the series of pipe commands to tie the various preformatters (the ones handling tables, pictures, and such) together with either troff or nroff. If it was sent to nroff, then the output was piped to more. Later changes (when disk space was available) system installation would preformat the man pages into ascii so that "man" only needed to become "more <manpath>/<section>/<page>" or the piped form if the page didn't exist already formatted. Formatting this way was nice - as it eliminated the rather CPU bound formatters... but it also meant that if you were printing you got the plain ascii... with the not so nice formatting.

troff, the preprocessors, and the macros defining the text all predated TeX, but produced high quality output. A large number of UNIX textbooks were written using it for the formatter. Most of the current Linux books still follow the style laid down by Bell Labs, though they may not use troff anymore.

Diantre 05-24-2013 04:53 PM

Thanks for that information jpollard. Then, would it be correct to say that the `...' syntax used today by TeX, Texinfo and groff is inherited from the original Unix utilities nroff/troff?

jpollard 05-24-2013 06:22 PM

TeX is totally separate. It was specifically developed for formatting mathematics.

Texinfo and groff do inherit - especially groff. Texinfo is not directly related, only the resulting format is similar due to it using ascii for output: http://www.gnu.org/software/texinfo/

I believe the man pages can still be processed by groff, most of the equations/diagrams are no longer used, so try a "zcat /usr/share/man1/<somthing.1.gz> groff -X -man -". Note, some things might be missing, (gxditview for instance) for that to work. If it doesn't you can use "groff -man -", dropping the -X and redirect the output to a file as it will be postscript. You can use a postscript viewer to look at it; or just print it.

The first UNIX system I got my hands on (UNIX v6) had the man pages on it.. so I printed them. For about a year that was my UNIX reference.


All times are GMT -5. The time now is 03:52 PM.