Search code examples
linuxshellfreebsd

dot command (.) not found on FreeBSD 9.3


On FreeBSD 9.3, I tried to used the dot command (.) on the root user (root@myserver#) but I received the following error:

> .: Command not found.

However, as a 'non-root` (#) user it works fine! What is going on?

$PATH - i point to /root and now ,i test on ec2 freebsd 9.3 dot command (.) is work but build server target on virsualbox can't found

I solve by use 'su username_root_login' and dot command (.) is work perfectly.


Solution

  • The . ("dot") command is built into the Bourne shell (sh) and into shells derived from it (bash, ksh, zsh, etc.). It reads and executes commands from a specified file. Unlike executing a file as a script, . executes the commands in the context of the current shell process. In some shells, source is equivalent to ..

    csh and its derivative tcsh do not have . as a built-in command. They do have an equivalent source command -- but that's not likely to be a solution, since either . filename or source filename executes commands in the current shell process, and the commands have to be valid for the current shell. sh and csh are similar for some simple commands, but for anything complex (if statements, loops, some kinds of I/O redirection, etc.) they implement incompatible languages. If you have a script meant to be executed from sh or bash using . filename, you won't be able to execute from csh or tcsh, even by using source filename.

    You're probably getting the error because the root account's default shell is /bin/csh or /bin/tcsh (I think that's typical for BSD-based systems). Your own non-root account probably has some Bourne-based shell as its default. You can find out what your default shell is by typing echo $SHELL at a prompt.

    On my system, I get a different error message when I try to use . filename from a csh or tcsh prompt but you could have a version that behaves differently.

    That explains why you're getting an error. It doesn't tell you how to fix it, but you haven't really given us enough information for that. If you really need to source a file, you have to be running a shell that's compatible with the commands in that file. You might need to execute, say, /bin/bash from the root shell prompt and then use the . command. But without more information, I can't tell whether that makes sense.

    What script are you trying to source? What is it supposed to do? Are you sure it needs to be sourced rather than executed?