- What are the conventional meanings for symbols used to show commands’ syntax?
- 3 Answers 3
- linux syntax
- What are the basic command in Linux?
- What Is syntax of command?
- How do you write commands in Linux?
- What is the difference between Linux and Unix?
- How do I install Linux?
- Which is the best Linux OS for beginners?
- What are commands?
- How do I run Java on Linux?
- What is an example of syntax?
- What is basic syntax in Python?
- What is the general format of UNIX command syntax?
- What does the syntax «|&» mean in shell language?
- 3 Answers 3
- Pipelines
What are the conventional meanings for symbols used to show commands’ syntax?
I am looking for some sort of «syntax key» for command line tools on GNU/Linux, something like this document that Microsoft has: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/command-line-syntax-key. For instance, text inside square brackets is used in Microsoft command line syntax documentation to represent optional items. Text in square braces is a set of required items and you must choose one. And so forth. What are the symbols used to indicate command line syntax in GNU/Linux, and what does each symbol mean?
That syntax key is a key/legend for other documentation—if you want the shell syntax, you should read the man page for the shell you use (bash, dash, zsh, etc.). For specific utilities, again, man pages.
@XTian, take a look at man man and just read the «synopsis» section, and pretend you didn’t already understand what the square brackets and vertical bars are supposed to mean. It would be (and is for beginners) utterly baffling. This is a great question; I’ve edited to make the essence of it more clear.
POSIX has a section about this called «Utility Argument Syntax»: pubs.opengroup.org/onlinepubs/9699919799/basedefs/…
3 Answers 3
Here is an excerpt from man 7 man-pages , which describes the conventional meanings for sections within man pages:
SYNOPSIS A brief summary of the command or function's interface. For commands, this shows the syntax of the command and its arguments (including options); boldface is used for as-is text and italics are used to indicate replaceable arguments. Brackets ([]) surround optional arguments, vertical bars (|) separate choices, and ellipses (. ) can be repeated.
I will add that how «boldface» and «italics» actually appear on your terminal is a different question. On my terminal, I get boldface for the as-is text and underlined text for the replaceable arguments; and on some terminals you may not get any such formatting at all.
- Optional items are enclosed in square brackets
- Vertical bars separate choices
- Ellipses mean an item or element can be repeated
Overall, the conventions are in fact very similar to the document from Microsoft that you cite.
Here is an example synopsis, from the man page for git diff :
SYNOPSIS git diff [options] [] [—] [. ] git diff [options] —cached [] [—] [. ] git diff [options] [—] [. ] git diff [options] git diff [options] [—no-index] [—]
The possible options are so numerous that the man page authors decided not to list them all in the synopsis, instead just saying [options] .
The multiple lines in the synopsis are because there are multiple possible (mutually exclusive) ways to use this particular command.
Everything in square brackets is optional, and everything in angle brackets is a placeholder.
(N.B.: Commits and blobs are types of objects that can be stored in Git; a blob represents a file’s contents and a commit represents a state of the entire set of files being tracked by Git. Not germane to your question but I’m mentioning this to avoid a mystery on terminology.)
Another example, the synopsis of the grep command, illustrates another convention: words written in ALL CAPS are sometimes used to show a placeholder (like the angle brackets in the git man page above).
SYNOPSIS grep [OPTIONS] PATTERN [FILE. ] grep [OPTIONS] -e PATTERN . [FILE. ] grep [OPTIONS] -f FILE . [FILE. ]
Here, again, there are three different ways to call the grep command. From reading the above, you can see that:
. means that apple is the pattern and orange and pear are both file names.
Likewise, you can see that in:
grep -e apple -e orange pear grapefruit
. apple and orange are both patterns, and pear and grapefruit are both files.
Now as for what that means in terms of what the command will do when given patterns and files, you have to read more of the man page than just the synopsis. But the synopsis lets you determine how the various arguments will be interpreted by the command you’re giving them to.
There are no absolute rules for the synopsis symbols, though. Here is the synopsis for sed :
SYNOPSIS sed [OPTION]. [input-file].
To make complete sense of that, you need to read further in the man page, where you will find:
If no -e, --expression, -f, or --file option is given, then the first non-option argument is taken as the sed script to interpret. All remaining arguments are names of input files; if no input files are specified, then the standard input is read.
linux syntax
The standard Linux command syntax is «command [options]» and then «». The «command [options]» and «» are separated by blank spaces. A Linux command is usually an executable program residing on the Linux disc. In our example, «ls» is the command name. . Arguments are separated by blank spaces.
What are the basic command in Linux?
- Listing directory contents ( ls command)
- Displaying file contents ( cat command)
- Creating files ( touch command)
- Creating directories ( mkdir command)
- Creating symbolic links ( ln command)
- Removing files and directories ( rm command)
- Copying files and directories ( cp command)
What Is syntax of command?
In the computer world, the syntax of a command refers to the rules in which the command must be run in order for a piece of software to understand it. For example, a command’s syntax may dictate case-sensitivity and what kinds of options are available that make the command operate in different ways.
How do you write commands in Linux?
- pwd — When you first open the terminal, you are in the home directory of your user. .
- ls — Use the «ls» command to know what files are in the directory you are in. .
- cd — Use the «cd» command to go to a directory. .
- mkdir & rmdir — Use the mkdir command when you need to create a folder or a directory.
What is the difference between Linux and Unix?
Linux is open source and is developed by Linux community of developers. Unix was developed by AT&T Bell labs and is not open source. . Linux is used in wide varieties from desktop, servers, smartphones to mainframes. Unix is mostly used on servers, workstations or PCs.
How do I install Linux?
- Step one: Download a Linux OS. (I recommend doing this, and all subsequent steps, on your current PC, not the destination system. .
- Step two: Create a bootable CD/DVD or USB flash drive.
- Step three: Boot that media on the destination system, then make a few decisions regarding the installation.
Which is the best Linux OS for beginners?
- Zorin OS. Based on Ubuntu and Developed by Zorin group, Zorin is a powerful and user-friendly Linux distribution that was developed with new Linux users in mind. .
- Linux Mint. .
- Ubuntu. .
- Elementary OS. .
- Deepin Linux. .
- Manjaro Linux. .
- CentOS.
What are commands?
Commands are a type of sentence in which someone is being told to do something. There are three other sentence types: questions, exclamations and statements. Command sentences usually, but not always, start with an imperative (bossy) verb because they tell someone to do something.
How do I run Java on Linux?
- From Terminal install open jdk sudo apt-get install openjdk-7-jdk.
- Write a java program and save the file as filename.java.
- Now to compile use this command from the terminal javac filename.java. .
- To run your program that you’ve just compiled type the command below in terminal: java filename.
What is an example of syntax?
Syntax is the order or arrangement of words and phrases to form proper sentences. The most basic syntax follows a subject + verb + direct object formula. That is, «Jillian hit the ball.» Syntax allows us to understand that we wouldn’t write, «Hit Jillian the ball.»
What is basic syntax in Python?
- First Python Program. Let us execute programs in different modes of programming. .
- Python Identifiers. A Python identifier is a name used to identify a variable, function, class, module or other object. .
- Reserved Words. .
- Lines and Indentation. .
- Multi-Line Statements. .
- Quotation in Python. .
- Comments in Python. .
- Using Blank Lines.
What is the general format of UNIX command syntax?
UNIX command lines can be simple, one-word entries like the date command. They can also be more complex: you may need to type more than the command name.
Water
Hard water. is water that contains an appreciable quantity of dissolved minerals (like calcium and magnesium). Soft water. is treated water in whi.
Java
JavaScript can be used to do neat things like creating animation in HTML. . JavaScript code is run on a browser only, while Java creates application.
Cigar
Both products contain tobacco. A main difference is that a cigar is wrapped in a tobacco leaf or a material containing tobacco, but cigarettes are wra.
Interesting articles, news and reviews dedicated to the comparison of popular things. Expand your horizons and learn something new every day
What does the syntax «|&» mean in shell language?
Recently, I am installing the PC^2 on my Ubuntu14.04LTS to make up our university’s ACM-ICPC Contest environment. But when I run the shell file «pc2server», the system gives me an error alert which is
pc2server: 27: pc2server: Syntax error: "&" unexpected
java -d64 -version |& grep -q "Error" && JAVA32=1
3 Answers 3
Pipelines
A pipeline is a sequence of one or more commands separated by one of the control operators | or |& . The format for a pipeline is:
[time [-p]] [ ! ] command [ [|│|&] command2 . ]
The standard output of command is connected via a pipe to the standard input of command2. This connection is performed before any redirections specified by the command (see REDIRECTION below). If |& is used, the standard error of command is connected to command2’s standard input through the pipe; it is shorthand for 2>&1 | . This implicit redirection of the standard error is performed after any redirections specified by the command.
Check your hash-bang line. Plain sh doesn’t support |& .
Thanks a lot, but now I find that if I delete the & or replace the |& to the 2>&1 | , the shell code will be right. Why?
It is the Bourne shell. The PC^2 system pc2.ecs.csus.edu is developed by California State University and I think maybe they would not make mistakes.
The hash-bang line is #!/bin/sh . ( sh is the Bourne shell, bash is the Bourne again shell). I think I got it, thanks a lot!
Please check answer of John. Here I am adding example for detail understating.
# cat /tmp/test1 cat: /tmp/test1: No such file or directory # cat /tmp/test1 2> /dev/null | grep "No such file or directory" # cat /tmp/test1 2> /dev/null |& grep "No such file or directory" cat: /tmp/test1: No such file or directory
First command returns error as file does not exist (stderr output from command).
Second command do not return any output as stderr of cat command is redirect /dev/null, so grep command do not get stderr of cat command through pipe.
Third command returns output even stderr of cat command is redirected to /dev/null because of pipe with ampersand (|&). It connects stdout and stderr of command1 to command2’s stdin; The implicit redirection of the standard error is performed after any redirections specified by the command.