微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux – 命令可以从Shell脚本运行,但不能从命令行运行?

我在发布之前很快搜索了这个,但找不到任何类似的帖子.如果它们存在,请告诉我.

正在执行的命令看起来非常简单.目录列表用作函数的输入.

该目录包含一堆名为“epi1_mcf_0 ###.nii.gz”的文件

命令行版本(bash在执行时运行):

fslmerge -t output_file `ls epi1_mcf_0*.nii.gz`

Shell脚本版本:

#!/bin/bash
fslmerge -t output_file `ls epi1_mcf_0*.nii.gz`

命令行版本失败,但shell脚本完美无缺.

错误消息特定于该功能,但无论如何它都包含在内.

** ERROR (nifti_image_read): Failed to find header file for 'epi1_mcf_0000.nii.gz'
** ERROR: nifti_image_open(epi1_mcf_0000.nii.gz): bad header info
Error: Failed to open file epi1_mcf_0000.nii.gz
Cannot open volume epi1_mcf_0000.nii.gz for reading!

我对这个问题感到非常沮丧(在我发现有一种方法可以使命令工作之后,我不太感到沮丧).

任何帮助,将不胜感激.

(或者是普遍认为应该在“fslmerge”函数中查找问题?)

解决方法:

(我先在评论中提到了这一点,但是我会做出答案,因为它有所帮助!)

你有定义的shell别名吗? (类型别名)这些将影响在命令行键入的命令,但不会影响脚本.

Linux经常将ls定义为ls –color.这可能会影响输出,因为颜色代码通过常规输出流作为转义码发送.如果使用ls –color = auto,它将自动检测其输出是否为终端.来自man ls:

By default, color is not used to distinguish types of files. That is
equivalent to using --color=none. Using the --color option without the
optional WHEN argument is equivalent to using --color=always. With
--color=auto, color codes are output only if standard output is connected to a terminal (tty).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐