user9283041
user9283041

Reputation:

Combine two commands for the same line in Linux

I need to execute two commands in the same line from the terminal. But it executed only the first command.

./build.py || cd /ns-3.20

That command only build was working and doesn't navigate to next directory.

Where am I get wrong?

Upvotes: 0

Views: 2482

Answers (5)

Prabhakar Lad
Prabhakar Lad

Reputation: 1438

Try the below command:

(./build.py &) ; cd /ns-3.20

Upvotes: 0

Walter A
Walter A

Reputation: 20002

With ./build.py || cd /ns-3.20 you only go to /ns-3.20 when the first command fails.
Is /ns-3.20 a directory you can access and has some files you need for repairing the build?
When you want to go to that directory only after success, use &&. When you want there independant of the result, use ;.

Upvotes: 0

Joe
Joe

Reputation: 7798

I would probably do:

./build.py && cd /ns-3.20

That way you only change directory if the build succeeds.

Upvotes: 1

you can use & :

 ./build.py & cd /ns-3.20

Upvotes: 0

Maroun
Maroun

Reputation: 95958

Change | to ;:

./build.py; cd /ns-3.20

Upvotes: 1

Related Questions