标准输出
方法一:
注意cat命令外面的那个引号是反引号,键盘上数字1旁边那个
xxx@xxx-desktop:~/temp$ aaa=`cat 123`
xxx@xxx-desktop:~/temp$ echo $aaa
abc
方法二:
xxx@xxx-desktop:~/temp$ ccc=$(cat 123)
xxx@xxx-desktop:~/temp$ echo $ccc
abc
返回值
$ cat test3
#!/bin/bash
return 123
$ source test3
$ echo $?
123
# `.` 和 source 是一样的
$ . test3
$ echo $?
123
# 直接运行 test3, 或者从bash 运行会报错,只能用source 执行
$ ./test3
./test3: line 2: return: can only `return' from a function or sourced script
$ bash test3
./test3: line 2: return: can only `return' from a function or sourced script
本文详细介绍了在bash脚本中如何使用特殊命令如`cat`和`return`,以及如何通过`$?`获取返回值。包括了通过反引号和赋值变量的方法来调用命令,并解释了`source`命令的作用和限制。
1689

被折叠的 条评论
为什么被折叠?



