1

i'm relearning some linux stuff, i recall that after i make edits to this file, i should issue a command that reloads the file and checks it for errors for safety reasons. Anyone know what the command is? I think the command is "source". However, when I su to root, and type in "source", it says it cannot find it. How do I make the Path include/find it?

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300
user8160
  • 329
  • 5
  • 13

1 Answers1

3

I think that source is a bash builtin, so if you aren't finding it when you are logged in as root, then you might not be running bash. You can try starting a bash shell just by typing bash. Or try the syntax . /etc/profile instead. Example (notice the space between the dot and /etc/profile):

jed@jed-osx:~$ . /etc/profile

Since source didn't work for you, I'm guessing you aren't running bash when logged in as root. You can determine this with echo $SHELL. Here is an example from my OSX system:

jed@jed-osx:~$ echo $SHELL
/bin/bash

Here is an example from a FreeBSD system:

FreeBSDBox[1001] # echo $SHELL
/bin/csh
Jed Daniels
  • 7,282
  • 2
  • 34
  • 42
  • the dot (.) did it, is it possible to explain a little how/why it works this way, the dot thing ahead of /etc/profile (./etc/profile)? – user8160 Jun 18 '10 at 22:39
  • Did you do it with a space between the dot and the `/etc/profile`? That is what I was suggesting, and I actually learned that it is a shortcut for the `source` bash builtin with a question on stackoverflow (http://stackoverflow.com/questions/2518127/how-do-i-reload-bashrc-without-logging-out-and-back-in). If you did it without the space, then you were basically just executing /etc/profile as a script, which will work just the same, if it is executable. – Jed Daniels Jun 18 '10 at 22:57
  • i issued "source ./etc/profile" and it worked, the command was found and the file reloaded. You are saying I could have ". /etc/profile"? – user8160 Jun 18 '10 at 22:59
  • Yes, I suspect you could have run ". /etc/profile", but now I'm curious: what exactly did you try that failed and what was the error message? I thought your initial question was saying that "source" wasn't found, but now I'm thinking it was something else. – Jed Daniels Jun 18 '10 at 23:06
  • 2
    "which will work just the same, if it is executable" - No, because the changes made to its environment won't persist in the current environment. That's the purpose of using `source` or `.`. If a script sets variables or does `cd`, for example, then exits, the interactive shell (or parent script) doesn't see those changes. If it's sourced, it's as if the commands it contains were typed at the command line (or included directly in the parent script). – Dennis Williamson Jun 19 '10 at 00:24
  • @Dennis thanks for setting me straight, I wasn't really thinking hard enough about it. If the script being run sets variables, then does an export of those variables, those will be seen by the parent (shell|script), correct? – Jed Daniels Jun 19 '10 at 00:28
  • 2
    No, `export` affects what is visible by child processes. The parent doesn't see the changes even if the variable is marked for export. See my answer [here](http://superuser.com/questions/143413/linux-environment-variables/143418#143418) for a discussion and demonstration. – Dennis Williamson Jun 19 '10 at 02:02