Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.


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 test.sh | bash -s hi bye
source test.sh hi bye
share|improve this question
Is this a homework question? –  mdpc Jun 10 '13 at 18:18
@mdpc meta.askubuntu.com/questions/6520/… –  StuartHa Jun 10 '13 at 22:31

1 Answer 1

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 test.sh
$ unset myVariable; source test.sh; echo ${myVariable:-null}
$ unset myVariable; bash -s < test.sh; 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.