如何从一个bash函数返回一个字符串值 [英] How to return a string value from a bash function
本文介绍了如何从一个bash函数返回一个字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从一个bash函数返回一个字符串。
我会写在Java中的例子来说明我想要做的:
公共字符串getSomeString(){
返回tadaa
}字符串变量= getSomeString();
下面在bash作品中的例子,但有没有更好的方式来做到这一点?
功能getSomeString {
回声tadaa
}变量= $(getSomeString)
解决方案
有没有更好的办法,我知道的。巴什只知道状态codeS(整数)和字符串写入标准输出。
I'd like to return a string from a bash function.
I'll write the example in java to show what I'd like to do:
public String getSomeString() { return "tadaa"; } String variable = getSomeString();
The example below works in bash, but is there a better way to do this?
function getSomeString { echo "tadaa" } VARIABLE=$(getSomeString)
解决方案
There is no better way I know of. Bash knows only status codes (integers) and strings written to the stdout.
这篇关于如何从一个bash函数返回一个字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文