解释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后获取字符串