newbie script question

Levin Fritz levinfritz at mediales.net
Sun Jan 25 18:08:56 UTC 2004


Hi,
there's several ways to start a script from the shell. You can call the
shell and give it the name of the script as a parameter, like this:
sh linux.sh
Or make the script executable (eg, chmod +x linux.sh) and call it with
./linux.sh      (from the directory the script is in)
If you type just "linux.sh", then the shell will search in your search
path only, not in the current directory. "echo $PATH" will print the
search path.

If you start your script that way, sh will create a new shell, run the
commands from the script in the new shell and return. So, if all your
script does is change the directory, this won't help you: sh will create a
new shell, change the directory and return to your shell, which is still
in the old directory.

You could use the source builtin (eg, "source linux.sh"); that will
execute the commands in the script without creating a new shell. ".
linux.sh" does exactly the same as "source linux.sh".

You could also write the commands in a bash function and put it in
$HOME/.bashrc (assuming you're using bash). Like this:
function linux {
  cd /mnt/whereever
}
Then just typing "linux[Enter]" in bash will do the trick.

Hope that helps,
Levin





More information about the fedora-list mailing list