is there a way to check if a bash script is complete or not?

后端 未结 4 850
囚心锁ツ
囚心锁ツ 2021-01-03 21:08

I\'m trying to implement a REPL (read-eval-print loop) in bash. If such a thing already exists, please ignore the following and answer this question with a pointer to it.

4条回答
  •  遥遥无期
    2021-01-03 21:35

    bash -n -c "$command_text"
    

    ...will determine whether your $command_text is a syntactically valid script without actually executing it.


    Note that there's a huge breadth of space between "syntactically valid" and "correct". Consider adopting something like http://shellcheck.net/ if you want to properly parse the language.

提交回复
热议问题