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
Variables 在bash中使用for循环中的变量_Variables_For Loop - Fatal编程技术网

Variables 在bash中使用for循环中的变量

Variables 在bash中使用for循环中的变量,variables,for-loop,Variables,For Loop,简单问题: 从编号列表中获取编号(i);然后用每个数字做某事 for i in list_of_number;do cat file|head -$(($i+1))|tail -1;done 这似乎是对的,但实际上不起作用。这里有什么问题? thx这样做会将编号的列表视为一个字符串;我假设这是一个包含要循环的数字列表的文件 请尝试: for i in `cat list_of_number`;do cat file|head -$(($i+1))|tail -1;done 对于“猫列表”中的“

简单问题:

从编号列表中获取编号(i);然后用每个数字做某事

for i in list_of_number;do cat file|head -$(($i+1))|tail -1;done
这似乎是对的,但实际上不起作用。这里有什么问题?
thx

这样做会将编号的列表视为一个字符串;我假设这是一个包含要循环的数字列表的文件

请尝试:

for i in `cat list_of_number`;do cat file|head -$(($i+1))|tail -1;done 对于“猫列表”中的“猫编号”;做cat文件|头-$($i+1))|尾-1;完成
别担心,我总是犯这样的错误。Bash可能是相当不可原谅的。