简体   繁体   中英

how to write bash && & in one line

how to write this in one line?

reboot -d 5 -f &  ;echo 666

then it tells me

-sh: syntax error: unexpected ";"

I use follow replace before to test to avoid reboot and easy to test

 echo 555 & ; echo 666
-sh: syntax error: unexpected "; 

I have try others

[root@EPC-M6Y2C ~]# `echo 555 & `&&  echo 666
-sh: 555: not found
[root@EPC-M6Y2C ~]# `echo 555 & ` ;  echo 666
-sh: 555: not found
666



Both & and ; terminate lists. & causes the list to run in the background, ; in the foreground.

If you use both, the & terminates the list and the ; tries to terminate an empty list, which is not allowed.

Just drop the ; :

reboot -d 5 -f & echo 666

You would get the same error if you just wrote an isolated

;

For the same reason, you can not write ie echo x;;echo y . If you want to write an empty statement (no-op), use : as a placeholder, ie

echo x; :; echo y 

works fine. In your case, this would be

reboot -d 5 -f & : ;echo 666

However, I would simply drop the no-op and write

reboot -d 5 -f & echo 666

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM