Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/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
如果存在特定字符,则使用bash_Bash - Fatal编程技术网

如果存在特定字符,则使用bash

如果存在特定字符,则使用bash,bash,Bash,我正在创建一个脚本来自动划分硬盘驱动器 现在,我遇到了以下问题: 我需要检查文本文件中是否存在“.”。(所以就点吧)。 实现这一目标的最佳方式是什么 例如: hdhelft=`cat /sometextfile` if grep "." $hdhelft then hdhelf2=something fi 不需要将文件读入变量,除非这是您真正想要的。从你的代码中不完全清楚你想要什么,但这是我的解释。使用-F标志对grep进行解释。作为一个文本,并且-q,因此它不

我正在创建一个脚本来自动划分硬盘驱动器

现在,我遇到了以下问题:

我需要检查文本文件中是否存在“.”。(所以就点吧)。 实现这一目标的最佳方式是什么

例如:

hdhelft=`cat /sometextfile`
if grep "." $hdhelft    
then    
hdhelf2=something    
fi    

不需要将文件读入变量,除非这是您真正想要的。从你的代码中不完全清楚你想要什么,但这是我的解释。使用
-F
标志对
grep
进行解释。作为一个文本,并且
-q
,因此它不会给出任何输出(只是yes或no)。此外,如果您确实希望
$hdhelft
包含文件的内容,请使用
$(您需要转义
字符,因为grep将其解释为“任何字符”。因此,请使用:

hdhelft=$(</sometextfile)
if grep -qF '.' /sometextfile; then
    hdhelf2=something
fi
grep '\.' yourfile