Home > OS >  How can I generate a list of every valid syntactic operator in Bash including input and output?
How can I generate a list of every valid syntactic operator in Bash including input and output?

Time:11-01

I would like to generate a list of every “syntactic operator” in the bash language, unless I’m misusing terminology. I mean I want to see a list of every symbol or string that the bash compiler recognises and knows what to do with, including commands like “ls” or just a symbol like “*”. I also want to see the inputs and outputs for each symbol, i.e., some commands are executed in the shell prompt by themselves, but what data type do they return? And some require a certain data type to standard input.

I want to do this just as a rigorous way to study the language.

How could I do this?

CodePudding user response:

I mean I want to see a list of every symbol or string that the bash compiler

Bash is not a compiler. It and every other shell I know are interpreters of various languages.

recognises and knows what to do with, including commands like “ls” or just a symbol like “*”. I also want to see the inputs and outputs for each symbol, i.e., some commands are executed in the shell prompt by themselves, but what data type do they return?

All commands executed by the shell have an exit status, which is a number between 0 and 255. This is as close to a "return type" as you get. Many of them also produce idiosyncratic output to one or two streams (a standard output stream and a standard error stream) under some conditions, and many have other effects on the shell environment or operating environment.

And some require a certain data type to standard input.

I can't think of a built-in utility whose expected input is well characterized as having a particular data type. That's not really a stream-oriented concept.

I want to do this just as a rigorous way to study the language.

If you want to rigorously study the language, then you should study its manual, where everything you describe has already been compiled. You might also want to study the POSIX shell command language manual for a slightly different perspective, which is more thorough in some areas, though what it documents differs in a few details from Bash's default behavior.

If you want to compile your own summary of Bash syntax and behavior, then those are the best source materials for such an effort.

CodePudding user response:

You can get a list of all reserved words and syntactic elements of bash using this trick:

help -s '*' | cut -d: -f1

Or more accurately:

help -s \* | awk -F ': ' 'NR>2&&!/variables/{print $1}'
  •  Tags:  
  • bash
  • Related