Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.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 使用'at';执行bash脚本_Linux_Bash_Batch Processing - Fatal编程技术网

Linux 使用'at';执行bash脚本

Linux 使用'at';执行bash脚本,linux,bash,batch-processing,Linux,Bash,Batch Processing,我制作了一个bash脚本,它调用jvm来执行一个jar程序。剧本写得很好。我想在某个时候使用prog`at'来执行bash脚本,但该脚本只能部分工作: #!/bin/bash touch hello.world while read line do touch another.hello.world name=$line ... done < "/users/me/readin.txt" 只生成了hello.world文件,但没有生成另一个.hello.world文件。

我制作了一个bash脚本,它调用jvm来执行一个jar程序。剧本写得很好。我想在某个时候使用prog`at'来执行bash脚本,但该脚本只能部分工作:

#!/bin/bash

touch hello.world
while read line
do
    touch another.hello.world
    name=$line
...
done < "/users/me/readin.txt"

只生成了hello.world文件,但没有生成另一个.hello.world文件。因此,我的脚本或命令使用中一定有问题。我该怎么办?

没有创建另一个.hello.world文件的唯一可能性是while循环的迭代至少没有发生一次

所以输入文件
/users/me/readin.txt
可能为空

我建议您使用
set-x
选项执行代码,您将找到原因。它将显示正在执行的跟踪

#!/bin/bash

touch hello.world
set -x
while read line
do
    touch another.hello.world
    name=$line
...
done < "/users/me/readin.txt"
set +x
#/bin/bash
触摸hello.world
集合x
读行时
做
触摸另一个世界
name=$line
...
完成
为什么您认为有什么问题
at
脚本没有标准输入,因此在运行read循环时,
中当然没有任何内容;除非你从一个文件重定向,否则它没有可以迭代的输入——如果你重定向循环的输入,你在这里给出的例子并没有显示它。它对我很有用。
readin.txt
的内容是什么?@digitaltrade是由\t分隔的多行文本。此脚本曾经在另一个linux设备上工作过,但现在无法工作。是否有可能输入和脚本文件被复制到windows设备中或同时从windows设备中复制*nix使用“\n”作为行分隔符,而windows使用“\r\n”。当两者混合时,混乱和无法解释的失败接踵而至。使用dos2unix或unix2dos实用程序可能会对您的文件进行排序。请尝试将读取行时的
更改为读取行时的
,或将
<“/users/me/readin.txt”
更改为
<
#!/bin/bash

touch hello.world
set -x
while read line
do
    touch another.hello.world
    name=$line
...
done < "/users/me/readin.txt"
set +x