What is the difference between “source” and “.” in bash?

1
Shell is just another word for the UI of an operating system. Strictly speaking, a GUI is as much of a shell as a command-line interface is, but we tend to mainly use the term for the latter.

Bash (Bourne Again SHell) is a particular implementation of a CLI shell, based on an older implementation called Bourne (which is still shipped in Linux distributions; you have used it if you ever called a script with sh). It's the analogous of using nautilus as your file manager. File manager is the generic term, Nautilus is the specifing program you're using.

The Windows command-line is also a shell, but being for another OS means it uses the corresponding interface (in this case, Windows API), which is different than the Unix/Linux shells (POSIX API, aka the kernel-user space API), therefore they're not interchangeable.

You can however implement a version of Bash that uses the Windows API, which is what Cygwin Bash...

0 0
2

1) What is Linux?

Linux is an operating system based on UNIX, and was first introduced by Linus Torvalds. It is based on the Linux Kernel, and can run on different hardware platforms manufactured by Intel, MIPS, HP, IBM, SPARC and Motorola. Another popular element in Linux is its mascot, a penguin figure named Tux.

2) What is the difference between UNIX and LINUX?

Unix originally began as a propriety operating system from Bell Laboratories, which later on spawned into different commercial versions. On the other hand, Linux is free, open source and intended as a non-propriety operating system for the masses.

3) What is BASH?

BASH is short for Bourne Again SHell. It was written by Steve Bourne as a replacement to the original Bourne Shell (represented by /bin/sh). It combines all the features from the original version of Bourne Shell, plus additional functions to make it easier and more convenient to use. It has since been adapted as the default...

0 0
3

When working with Linux, Unix, and Mac OS X, I always forget which bash config file to edit when I want to set my PATH and other environmental variables for my shell. Should you edit .bash_profile or .bashrc in your home directory?

You can put configurations in either file, and you can create either if it doesn’t exist. But why two different files? What is the difference?

According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

What is a login or non-login shell?

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.

But, if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash...

0 0
4

shell in the uk

What is the difference between sh and source? 12 gauge shell holder belt

source: source filename [arguments] Read and execute commands from FILENAME and return. The pathnames in $PATH are used to find the directory containing FILENAME. If any ARGUMENTS are supplied, they become the positional parameters when FILENAME is executed.

And for man sh:

NAME bash - GNU Bourne-Again SHell SYNOPSIS bash [options] [file] COPYRIGHT Bash is Copyright (C) 1989-2004 by the Free Software Foundation, Inc. DESCRIPTION Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh). Bash is intended to be a conformant implementation of the IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).

z shell...

0 0
5

I am trying to set up a cron job to run regression tests for software that usually runs in an interactive environment (CASA, for the morbidly curious: http://casa.nrao.edu/). I have a shell script, which, in MWE form (mwe.sh), does:

casapy -c mwe.py

where it is supposed to execute that script. casapy is a fairly complicated bit of business that does a lot of things internally, including importing and setting up an ipython client for multiprocessing.

Here is my problem: If I run the code interactively, i.e. type casapy -c mwe.py on the bash shell command line, it works. If I run:

source mwe.sh

the code still runs exactly as expected and performs the tests. Great!

If instead, I run

bash mwe.sh

the startup script hangs permanently. I've tracked this down to a few different locations in the startup script that all are capable of independently failing.

So, my question: What are the differences between starting commands in the interactive shell...

0 0
6

What is the difference between Linux and UNIX operating systems?

UNIX is copyrighted name only big companies are allowed to use the UNIX copyright and name, so IBM AIX and Sun Solaris and HP-UX all are UNIX operating systems. The Open Group holds the UNIX trademark in trust for the industry, and manages the UNIX trademark licensing program.

Most UNIX systems are commercial in nature.

Linux is a UNIX Clone

But if you consider Portable Operating System Interface (POSIX) standards then Linux can be considered as UNIX. To quote from Official Linux kernel README file:

Linux is a Unix clone written from scratch by Linus Torvalds with assistance from a loosely-knit team of hackers across the Net. It aims towards POSIX compliance.

However, “Open Group” do not approve of the construction “Unix-like”, and consider it misuse of their UNIX trademark.

Linux Is Just a Kernel

Linux is just a kernel. All Linux distributions...

0 0
7

KSH vs BASH

There are many “shells” in both Linux and Unix. Two kinds of these numerous shells are KSH and Bash.

KSH and Bash are shells in the field of computer programming. Basically, they are shells with their own set of commands and features. KSH and Bash are somewhat related to each other since KSH encompasses the features of .sh or Bourne shell, the predecessor of the Bash shell.

As shells, both have programmable shells and command processors in Linux and UNIX computer systems. They also carry out commands for use via a keyboard terminal or from a file.

KSH is also known as the Korn shell. The Korn shell was developed by David Korn, and it attempts to merge the features of fellow shells like C shell, TC shell and Bourne shell. It allows the developers to create new shell commands when needed.

Korn shell is developed many years before the emergence of the BASH shell. Because it is older than BASH, it has less resources, and it also attracts...

0 0
8

If you use bash for scripting you will undoubtedly have to use conditions a lot, for example for an if … then construct or a while loop. The syntax of these conditions can seem a bit daunting to learn and use. This tutorial aims to help the reader understanding conditions in bash, and provides a comprehensive list of the possibilities. A small amount of general shell knowledge is assumed.

Difficulty: Basic – Medium

Bash features a lot of built-in checks and comparisons, coming in quite handy in many situations. You’ve probably seen if statements like the following before:

if [ $foo -ge 3 ]; then

The condition in this example is essentially a command. It may sound strange, but surrounding a comparison with square brackets is the same as using the built-in test command, like this:

if test $foo -ge 3; then

If $foo is Greater then or Equal to 3, the block after ‘then’ will be executed. If you always wondered why bash tends to use -ge or -eq...

0 0
9

Git Basics

So, what is Git in a nutshell? This is an important section to absorb, because if you understand what Git is and the fundamentals of how it works, then using Git effectively will probably be much easier for you. As you learn Git, try to clear your mind of the things you may know about other VCSs, such as Subversion and Perforce; doing so will help you avoid subtle confusion when using the tool. Git stores and thinks about information much differently than these other systems, even though the user interface is fairly similar, and understanding those differences will help prevent you from becoming confused while using it.

Snapshots, Not Differences

The major difference between Git and any other VCS (Subversion and friends included) is the way Git thinks about its data. Conceptually, most other systems store information as a list of file-based changes. These systems (CVS, Subversion, Perforce, Bazaar, and so on) think of the information they keep as...

0 0
10

Short Answer

In your question, the second command uses neither the . shell built-in nor the source built-in. Instead, you are actually running the script in a separate shell, by invoking it by name (like any other executable file). This does give it a separate set of environment variables (though if you export an environment variable in its parent shell, it'll be included). If you change the / to a space, then that would run it with the . built-in, which is equivalent to source.

Extended Explanation

This is the syntax of the source shell built-in, which executes the contents of a script in the current shell (and thus with the current shell's environment variables):

source testenv.sh

This is the syntax of the . built-in, which does do the same thing as source:

. testenv.sh

However, this syntax runs the script as an executable file, launching a new shell to run it:

./testenv.sh

That is not using the . built-in. Rather, . is part of the...

0 0
11

Short answer: sourcing will run the commands in the current shell process. executing will run the commands in a new shell process. still confused? then please continue reading the long answer.

Terminology:

To clarify some common confusion about the syntax to execute and the syntax to source:

./myscript

Execute myscript provided that the file is executable and located in the current directory. The leading dot slash (./) denotes the current directory. This is necessary because the current directory is usually not in $PATH.

myscript

Execute myscript if the file is executable and located in some directory in $PATH.

source myscript

Source myscript. the file need not be executable but it must be a valid shell script. The file can be in current directory or in a directory in $PATH.

. myscript

Source myscript. This syntax is defined by POSIX. Bash defined source as an alias to the dot command.

Demonstration:

Consider myscript.sh...

0 0
12

The main difference with shell config files is that some are only read by "login" shells (eg. when you login from another host, or login at the text console of a local unix machine). these are the ones called, say, .login or .profile or .zlogin (depending on which shell you're using).

Then you have config files that are read by "interactive" shells (as in, ones connected to a terminal (or pseudo-terminal in the case of, say, a terminal emulator running under a windowing system). these are the ones with names like .bashrc, .tcshrc, .zshrc, etc.

bash complicates this in that .bashrc is only read by a shell that's both interactive and non-login, so you'll find most people end up telling their .bash_profile to also read .bashrc with something like

[[ -r ~/.bashrc ]] && . ~/.bashrc

Other shells behave differently - eg with zsh, .zshrc is always read for an interactive shell, whether it's a login one or not.

The manual page for bash explains the...

0 0
13

On Linux and other Unix-like systems you have a choice of multiple shells.

The shell is responsible not only for drawing your little prompt, but interpreting your commands, especially if you put in complicated logic like pipes, conditionals and so on.

bash is the most common shell used as a default shell for users of Linux systems. It is a spiritual descendent of other shells used throughout Unix history.

It's run, these days, from /bin/bash - any system with bash will have it accessible here.

It's not just users that use shells, though. Scripts (shell scripts) need shells to interpret them. When you run a shell script, your system needs to start up a shell process to execute your script.

The problem is, different shells have tiny little inconsistencies between them, and when it comes to running scripts, these can be a real problem. bash has quite a lot of scripting features that are unique only to bash, and not to other shells. This is fine, if...

0 0
14

Remember, functions are internal to a script and normally return from whence they were called by using the return statement. Calling an external script is another matter entirely, and scripts usually terminate with an exit statement.

The difference "between the return and exit statement in BASH functions with respect to exit codes" is very little. Both return a status, not values per se. A status of zero indicates success, while any other status (1 to 255) indicates a failure. The return statement will return to the script from where it was called, while the exit statement will end the entire script from whereever it is encountered.

return 0 # returns to where the function was called. $? contains 0 (success).

return 1 # returns to where the function was called. $? contains 1 (failure).

exit 0 # exits the script completely. $? contains 0 (success).

exit 1 # exits the script completely. $? contains 1 (failure).

If your function simply ends...

0 0
15

Background

In Linux (and Unix in general), there is a SuperUser named Root. The SuperUser can do anything and everything, and thus doing daily work as the SuperUser can be dangerous. You could type a command incorrectly and destroy the system. Ideally, you run as a user that has only the privileges needed for the task at hand. In some cases, this is necessarily Root, but most of the time it is a regular user.

su -

This command is used to login at root account.
By default, the Root account password is locked in Ubuntu. This means that you cannot login as Root directly or use the su command to become the Root user. However, since the Root account physically exists it is still possible to run programs with root-level privileges. This is where sudo comes in - it allows authorized users (normally "Administrative" users) to run certain programs as Root without having to know the root password.

See How to Enable Root Account.

sudo sh

This...

0 0
16

Source NAT changes the source address in IP header of a packet. It may also change the source port in the TCP/UDP headers. The typical usage is to change the a private (rfc1918) address/port into a public address/port for packets leaving your network.

Destination NAT changes the destination address in IP header of a packet. It may also change the destination port in the TCP/UDP headers.The typical usage of this is to redirect incoming packets with a destination of a public address/port to a private IP address/port inside your network.

Masquerading is a special form of Source NAT where the source address is unknown at the time the rule is added to the tables in the kernel. If you want to allow hosts with private address behind your firewall to access the Internet and the external address is variable (DHCP) this is what you need to use. Masquerading will modify the source IP address and port of the packet to be the primary IP address assigned to the outgoing interface....

0 0
17

A login shell is the first process that executes under your user ID when you log in for an interactive session. The login process tells the shell to behave as a login shell with a convention: passing argument 0, which is normally the name of the shell executable, with a - character prepended (e.g. -bash whereas it would normally be bash. Login shells typically read a file that does things like setting environment variables: /etc/profile and ~/.profile for the traditional Bourne shell, ~/.bash_profile additionally for bash†, /etc/zprofile and ~/.zprofile for zsh†, /etc/csh.login and ~/.login for csh, etc.

When you log in on a text console, or through SSH, or with su -, you get an interactive login shell. When you log in in graphical mode (on an X display manager), you don't get a login shell, instead you get a session manager or a window manager.

It's rare to run a non-interactive login shell, but some X settings do that when you log in with a display manager, so as to...

0 0