Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
2 and 3 are the same, it means the program will be executed by the current shell. Tcsh cannot understand 2) some other shells cannot understand 3).
1 means a new shell will be opened (child process) and that will execute foo.
The main difference is that using method 1 you can execute a script but your current shell will remain as it was before, using 2 or 3 you will be able to modify your actual environment (define functions, set variables ...)
The '.' notation in bash is just shorthand for 'source'. To 'source' a file is causing the current shell process to read it in mostly the same manner as if you had typed it interactively. This allows you to use that method when you need to alter the properties of the current shell session, such as changing directories or setting environment variables. When a script is 'run', as your "1)" method describes, it launches a child shell which executes the script, and then terminates. Any alteration of process properties is restricted to that child shell. Since the child shell terminates when the script completes execution, those changes vanish with it. Moreover, the child shell (like any process) is incapable of altering the properties of any other process, be it a parent, child or sibling.
Aha... When I have just installed an O.S. I must afterwards do some settings and install some software. For instance, one thing I do, is to install two programs: autojump and ytree. To save work, I could write a script like this:
## Linked to /bin/bash in my system.
### Pseudocode - I don't know how this is done
if ~/work does not exist
### Pseudocode END
cp /deb4/almacen/soft/ncd/autojump-v8.tar.gz ~/work
cp /deb4/almacen/soft/ncd/ytree-1.94.tar.gz ~/work
gzip -dv autojump-v8.tar.gz
gzip -dv ytree-1.94.tar.gz
tar -xvf autojump-v8.tar
tar -xvf ytree-1.94.tar
# Here I just edit ~/.bashrc and /root/.bashrc
# when working interactively. So here I do:
echo "source /etc/profile.d/autojump.bash" >> ~/.bashrc
echo "source /etc/profile.d/autojump.bash" >> /root/.bashrc
According to what has been said, it would be exactly the same if I source this script or I directly run it (methods 3) and 1) above). Am I right?
I rarely put build commands in scripts though, and I recommend against it as well. Unless you are positive your system is set up properly (all necessary dependencies), it could easily fail. The problem with scripts is, if a command fails, the script just keeps on going. For example, if your "make" fails because of a missing dependency, the script doesn't give a crap and goes straight to "make install". You should really be putting in some error checking if you want this to be a reliable tool.
Last edited by suicidaleggroll; 04-25-2014 at 11:26 PM.