Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

mkdir test
echo $1
echo $2

It appears that following two commands do the same things. Are they the same? If not, how could I alter my example to show the difference?

cat | bash -s hi bye
source hi bye
share|improve this question
Is this a homework question? – mdpc Jun 10 '13 at 18:18
@mdpc… – StuartHa Jun 10 '13 at 22:31
up vote 4 down vote accepted

The difference will be if you are trying to alter the environment of your current shell (i.e. set a shell or environment variable). For example

$ cat
$ unset myVariable; source; echo ${myVariable:-null}
$ unset myVariable; bash -s <; echo ${myVariable:-null}

This is what source is for: evaluate a script in the current shell. When you launch a new bash process, it cannot alter the parent process's environment.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.