Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解释bash变量赋值输出_Bash_Variables_Variable Assignment - Fatal编程技术网

解释bash变量赋值输出

解释bash变量赋值输出,bash,variables,variable-assignment,Bash,Variables,Variable Assignment,谁能解释一下原因吗 VBB:~ me$ test="zut"; echo $test; echo $test > test2; echo "echo test " $test2 输出为: zut echo test VBB:~ me$ 而不是 zut echo test zut VBB:~ me$ 因为echo$test>test2将输出写入名为test2的文件 这组命令实现了您所期望的功能: test="zut"; echo $test; test2=$test; echo "

谁能解释一下原因吗

VBB:~ me$ test="zut"; echo $test; echo $test > test2; echo "echo test " $test2
输出为:

zut
echo test
VBB:~ me$ 
而不是

zut
echo test zut
VBB:~ me$ 

因为
echo$test>test2
将输出写入名为test2的文件

这组命令实现了您所期望的功能:

test="zut"; echo $test; test2=$test; echo "echo test " $test2

因为
echo$test>test2
将输出写入名为test2的文件

这组命令实现了您所期望的功能:

test="zut"; echo $test; test2=$test; echo "echo test " $test2

除了第一个答案,您还可以在文件中为值指定一个变量

echo "$var" ; var= more test2

因此,您可以在写入文件test2后获取字符串。除了第一个答案之外,您还可以为文件中的值分配一个变量

echo "$var" ; var= more test2
所以您可以在写入文件test2后获取字符串