In bash, is there an equivalent of die “error msg”

前端 未结 5 835
面向向阳花
面向向阳花 2020-12-04 15:31

In perl, you can exit with an error msg with die \"some msg\". Is there an equivalent single command in bash? Right now, I\'m achieving this using commands: <

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 15:40

    Yep, that's pretty much how you do it.

    You might use a semicolon or newline instead of &&, since you want to exit whether or not echo succeeds (though I'm not sure what would make it fail).

    Programming in a shell means using lots of little commands (some built-in commands, some tiny programs) that do one thing well and connecting them with file redirection, exit code logic and other glue.

    It may seem weird if you're used to languages where everything is done using functions or methods, but you get used to it.

提交回复
热议问题