What Does "|" Mean in a Terminal Command Line

What does | mean in a terminal command line?

It is the pipe symbol. It separates two programs on a command line (see Pipelines in the bash manual), and the standard output of the first program (on the LHS of the pipe) is connected to the standard input of the second program (on the RHS of the pipe).

For example:

who | wc -l

gives you a count of the number of people or sessions connected to your computer (plus one for the header line from who). To discount the header line:

who | sed 1d | wc -l

The input to sed comes from who, and the output of sed goes to wc.

The underlying system call is pipe(2) used in conjunction with fork(), dup2() and the exec*() system calls.

What does (1) mean in terminal commands?

It's the "section" in which this man page is found.

  1. General commands
  2. System calls
  3. Library functions, covering in particular the C standard library
  4. Special files (usually devices, those found in /dev) and drivers
  5. File formats and conventions
  6. Games and screensavers
  7. Miscellanea
  8. System administration commands and daemons

And no, this is not related to the numbering of a process' file handles (such as 1 for stdout, 2 for stderr).

What is the meaning of command line options for python from the windows command prompt (example: -i, -m)

You can get a list of all the python command flags and what they do by typing

python --help

In the case of tkinter, you need to run with the -i flag because it will run in "interactive mode". This allows the windowed application to launch. The help says it best

-i : inspect interactively after running script; forces a prompt even
if stdin does not appear to be a terminal; also PYTHONINSPECT=x

Meanwhile -m launches a module as if it were a script.

-m mod : run library module as a script (terminates option list)

What does $@ mean in a shell script?

$@ is nearly the same as $*, both meaning "all command line arguments". They are often used to simply pass all arguments to another program (thus forming a wrapper around that other program).

The difference between the two syntaxes shows up when you have an argument with spaces in it (e.g.) and put $@ in double quotes:

wrappedProgram "$@"
# ^^^ this is correct and will hand over all arguments in the way
# we received them, i. e. as several arguments, each of them
# containing all the spaces and other uglinesses they have.
wrappedProgram "$*"
# ^^^ this will hand over exactly one argument, containing all
# original arguments, separated by single spaces.
wrappedProgram $*
# ^^^ this will join all arguments by single spaces as well and
# will then split the string as the shell does on the command
# line, thus it will split an argument containing spaces into
# several arguments.

Example: Calling

wrapper "one two    three" four five "six seven"

will result in:

"$@": wrappedProgram "one two    three" four five "six seven"
"$*": wrappedProgram "one two three four five six seven"
^^^^ These spaces are part of the first
argument and are not changed.
$*: wrappedProgram one two three four five six seven

What does the '$' mean in command line commands?

$ is not part of the command, it is just shown to illustrate terminal input. A full log of the guys entry would read something like

Dominic@stackoverflow$ sudo ap...

See the answer below https://stackoverflow.com/a/48215530/1117934, for a more complete explanation on the difference between $ and #.

what is | in Ubuntu or Linux in general

the symbol is called a "pipe".

The command df | grep is "piping" (redirecting) the standard output of the df command into the standard input of the grep command. In this example the grep command filters the output of the df command. Then the awk commands is for display/format purposes.

Inside the regular expression it is specific to the grep syntax since it is surrounded by quotes it is only considered as an argument passed to grep

Any way to exit bash script, but not quitting the terminal

The "problem" really is that you're sourcing and not executing the script. When you source a file, its contents will be executed in the current shell, instead of spawning a subshell. So everything, including exit, will affect the current shell.

Instead of using exit, you will want to use return.



Related Topics



Leave a reply



Submit