I need to find help for point command .
such as in . ./my_script.sh
(I mean the first point.)
I have already tried to find a man page using man .
and man \.
. How can I display a man page in which it explains the use of command .
?
First of all you should invoke type .
, you will probably get something like:
. is a shell builtin
Builtins are parts of your shell, they don't have their own manual pages. Some of them may seem to have them though, e.g. echo
is a builtin in Bash but most likely there is a separate executable like /bin/echo
in your system and in this case man echo
refers to the latter. These two echo
s are probably not strictly equivalent.
Your shell may provide information about any builtin via help
builtin; try help help
, help type
and finally:
help .
Builtins may also be listed in your shell's manual page. E.g. (in my Debian) Bash builtins are covered directly in man bash
, yet for Zsh builtins man zsh
tells me to run man zshbuiltins
. In general shells may or may not explain their builtins.
.
is a shell-built-in and This should be marked as answer because OP asks how to find help for . in *nix ?
.
Commented
Mar 22, 2018 at 11:45
type .
to demonstrate that some commands are shell builtins.
Commented
Mar 22, 2018 at 11:53
bash-builtins(1)
manual page, which is of a more convenient size.
Commented
Mar 22, 2018 at 14:06
Try using man sh
or man bash
or the man page for whatever shell you are using. (Maybe man $SHELL
.)
This is officially not called the "point" command, but the source
command. Searching for the word source
may be helpful.
e.g., bash man page (search for "each builtin command"), and you'll quickly find the documentation.
As for explaining the use, I can do that right here. I will just refer to this as the source
command, recognizing that it can be abbreviated to just a period when you're using some shells, and with some shells that command might need to be (because dot might be recognized but the entire word source
might not be).
If you use the source
command, your shell will read each line from the script file, and try to execute it. You need "read" permissions on the file. (It doesn't matter if you have "execute" permissions.) If you modify a variable, that is prone to affecting your current shell.
If, on the other hand, you just try to execute the file, then your shell will ask the operating system to take care of this request. This will require "execute" permissions. (On some systems, like OpenBSD, you won't need "read" permissions for this. On other systems, including many Unix variations, you will.) The file may need to start with an appropriate header (e.g., #!/bin/sh
) so the operating system recognizes this to be a script file. The operating system will execute a copy of the requested shell, and tell that shell to run the contents of the script. If the shell environment is changed (e.g., a variable gets a new value, the working directory is changed (with cd
), a file descriptor is redirected (with exec
), etc.), it will impact only the sub-shell that was called for the script, and can't modify the environment in the parent shell that called the script file.
source
in bash. In the POSIX specification, it's called "the dot command" (and the source
alias is not supported).
Commented
Mar 22, 2018 at 17:13
man bash
and then what, /.
? Not very useful. /source
would be useful, but for that you'd need to know that .
and source
are the same thing.
.
and it might be source
, but as @CharlesDuffy already mentioned, it's always .
in any POSIX-compliant shell and only has the alias source
in one shell.
Commented
Mar 24, 2018 at 17:40
No one else has mentioned it, as it's often forgotten.
Your biggest clue would of come from the helpful command whatis
.
tim@musha ~ $ whatis .
builtins (1) - bash built-in commands, see bash(1)
tim@musha ~ $ whatis source
builtins (1) - bash built-in commands, see bash(1)
tim@musha ~ $ whatis bash
bash (1) - GNU Bourne-Again SHell
tim@musha ~ $ whatis lynx
lynx (1) - a general purpose distributed information browser for the World Wide Web
tim@musha ~ $ whatis linux
linux: nothing appropriate.
tim@musha ~ $ whatis whatis
whatis (1) - display one-line manual page descriptions
EDIT:
Some people have pointed out in the comments that this isn't in some distrobutions - maybe it's an installable package, or enabled some how - I had it by default in gentoo ;)
It includes the wonderful which - which tells you which executable is called, and whereis which gives you all the paths to a executable you name, and it's man pages (if it exists in multiple paths).
whatis .
returns man: 0703-307 . is not found.
Commented
Mar 22, 2018 at 16:43
whatis .
" gave ".: nothing appropriate.
" on OpenBSD, it resulted in 47 lines of output. For this specific example (using "whatis .
" in Gentoo), the results may happen to just be uncommonly good (meaning that this technique isn't generally as useful for many other example scenarios).
man source
will show the explanation that you need.
The dot is the same as the source command.
source
executes the script in the current shell instead of in a subshell (it's the usual way).
Using source
the variables set inside the script are preserved after the script has finished.
man source
work? Not in my Debian, hence the question.
Commented
Mar 22, 2018 at 10:34
source
upstream -- that's more likely something CentOS did.
Commented
Mar 22, 2018 at 17:14
man source
gives you man bash_builtins
, which doesn’t explain anything, but refers you to bash(1)
Commented
Mar 22, 2018 at 20:59
man source
gives me source(3tcl)
... type command
and then if the command is a builtin help command
is probably the proper way...
The .
is a synonym for the shell source
command and so in bash, its syntax is displayed by...
help source
It functions exactly like the include
and import
commands in other languages in that it reads the target file and interprets it as if it were part of the current script. Thus, that file will execute in its entirety before the commands in the rest of the current script.
It should usually be at the beginning of the current script and is most often used to load variables and/or function definitions.
help .
dot
. See the formal specification at pubs.opengroup.org/onlinepubs/009696699/utilities/dot.html.
is a command, specifically a shell builtin. In Bash it's equivalent tosource
..
is POSIX, not just bash. E.g. it's also in zsh and ksh.