What does the semicolon do when it is run in a bash command?

前端 未结 3 771
既然无缘
既然无缘 2020-12-19 17:28

For example, when running

echo a; echo b

in the terminal, its output is:

a
b

It seems to me that the semi

相关标签:
3条回答
  • 2020-12-19 17:45

    it's a way to simulate a newline.

    echo a; echo b
    

    is equivalent to

    echo a

    echo b

    0 讨论(0)
  • 2020-12-19 17:46

    The ; separates the two commands.

    echo a; echo b
    

    It lets the bash know that echo a and echo b are two separate commands and need to be run separately one after the other

    Try without semicolons

    $ echo a echo b
    a echo b
    

    Here the statement is taken as a single command echo and a echo b is passed as parameter to the echo

    0 讨论(0)
  • 2020-12-19 17:53

    It's a statement separator. You could also try

    sleep 1; echo a
    

    which will wait one second and then display a. As would

    sleep 1 && echo a
    
    0 讨论(0)
提交回复
热议问题