Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "echo 'hello'; ls" vs "echo 'hello' && ls"?

Tags:

bash

I wonder what the difference between

"echo 'hello'; ls"

and

"echo 'hello' && ls"

is? they both do the same thing

like image 621
never_had_a_name Avatar asked Aug 26 '10 09:08

never_had_a_name


1 Answers

"echo 'hello' && ls" means : execute "ls" if "echo 'hello'" runs successfully. To understand what is "successful" in bash. Try this :

bash> cd /
bash> echo $?

if the previous command runs successfully, you should see 0

After that, try this :

bash> asdfdf
bash> echo $?

You should see a non-zero value between 1 and 255. This means previous command didn't run successfully

On the other hand, "echo 'hello'; ls" means execute "ls" whether "echo 'hello'" runs successfully or not.

like image 66
Hendra Jaya Avatar answered Oct 17 '22 17:10

Hendra Jaya