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?

  • use `;` to sequence commands – Micha Wiedenmann Jan 29 '18 at 10:09
  • For sequential exectution use `./build.py; cd /ns-3.20`. the `|` is for chaining commands (unnamed pipe). – Picaud Vincent Jan 29 '18 at 10:10
  • duplicate of [Running multiple commands in one line in shell](https://stackoverflow.com/questions/5130847/running-multiple-commands-in-one-line-in-shell). Please search, or even *re*search by reading the basic documentation of your terminal, before asking such questions. – underscore_d Jan 29 '18 at 10:10

5 Answers5

1

Change | to ;:

./build.py; cd /ns-3.20
Maroun
  • 94,125
  • 30
  • 188
  • 241
  • @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? – Gerhard Jan 29 '18 at 11:10
1

I would probably do:

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

That way you only change directory if the build succeeds.

Joe
  • 7,378
  • 4
  • 37
  • 54
0

you can use & :

 ./build.py & cd /ns-3.20
  • [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 – Mohamed Rached Ben Cheikh Jan 29 '18 at 14:38
  • This is same exemples – Mohamed Rached Ben Cheikh Jan 29 '18 at 14:48
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 ;.

Walter A
  • 19,067
  • 2
  • 23
  • 43
  • 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` – Walter A Jan 29 '18 at 10:41
0

Try the below command:

(./build.py &) ; cd /ns-3.20
Prabhakar Lad
  • 1,248
  • 1
  • 8
  • 12