Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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
Linux 从shell脚本中的另一个变量创建变量_Linux_Bash_Tail - Fatal编程技术网

Linux 从shell脚本中的另一个变量创建变量

Linux 从shell脚本中的另一个变量创建变量,linux,bash,tail,Linux,Bash,Tail,在shell脚本中,我将输出存储为变量,如下所示 Test=$(/home/$USER/import.py $table) table= 123_test min_id=1 max_id=100 123_test,1,100 现在这个测试变量将有两行以上,如下所示 Test=$(/home/$USER/import.py $table) table= 123_test min_id=1 max_id=100 123_test,1,100 现在我想将测试变量的最后一行存储为另一个名为out

在shell脚本中,我将输出存储为变量,如下所示

Test=$(/home/$USER/import.py $table)
table= 123_test
min_id=1
max_id=100
123_test,1,100
现在这个测试变量将有两行以上,如下所示

Test=$(/home/$USER/import.py $table)
table= 123_test
min_id=1
max_id=100
123_test,1,100
现在我想将测试变量的最后一行存储为另一个名为output的变量

我试过下面的方法。但是没有得到预期的结果

output=`$test | tail -n 1`
我们可以从shell脚本中的另一个变量创建一个变量吗。如果是,我们如何做呢?

使用echo将变量传递到另一个命令

output=$(echo "$test" | tail -1)
或此处的字符串:

output=$(tail -1 <<<"$test")
简单地说:output=${Test*$'\n'}或者您可以这样写:output=`echo$Test | tail-n1`或echo${Test*$'\n'}