0

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?

3
  • use ; to sequence commands Commented Jan 29, 2018 at 10:09
  • For sequential exectution use ./build.py; cd /ns-3.20. the | is for chaining commands (unnamed pipe). Commented Jan 29, 2018 at 10:10
  • duplicate of Running multiple commands in one line in shell. Please search, or even research by reading the basic documentation of your terminal, before asking such questions. Commented Jan 29, 2018 at 10:10

5 Answers 5

1

Change | to ;:

./build.py; cd /ns-3.20
Sign up to request clarification or add additional context in comments.

1 Comment

@M.David then you are "doesn't working" something wrong. What does that mean? Does not work is not a problem, unless we know what the does not work mean, errors? what happens?
1

I would probably do:

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

That way you only change directory if the build succeeds.

Comments

0

you can use & :

 ./build.py & cd /ns-3.20

2 Comments

[root@f]# echo test test [root@f]# echo test & echo test2 [1] 14396 test2 test [root@f]# echo test && echo test2 test test2 [1]+ Fini echo test [root@f]# true ; echo test test [root@f]# false ; echo test test [root@f]# false & echo test [1] 14436 test [root@f]# false && echo test [1]+ Termine 1 false [root@f]# true && echo test test
This is same exemples
0

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 ;.

1 Comment

What is your error? Does cd /ns-3.20 work, or should this be changed into cd $HOME/ns-e.20 ? Does ./build.py execute ? Try echo "Test"; pwd;cd /tmp'pwd; cd;pwd
0

Try the below command:

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

Comments