读书人

在linux停将脚本设置为可执行

发布时间: 2013-11-05 14:40:42 作者: rapoo

在linux下将脚本设置为可执行
我有一个脚本文件 命名为first


本人刚学shell编程,脚本程序是照书上抄的。。调试还看不出来原理。

找到了 ,可爱的grep/shell没有识别出带有空格的文件名,
就是你上面的Ubuntu One被认为是两个文件(夹): Ubuntu 和 One .
只要在原来的文件中修改:

```
if grep -q POSIX $file #$file加对引号,变为下面的样子
if grep -q POSIX "$file"
```

我这双引号测试ok了.具体双引号还是单引号还是一个坑,得慢慢啃呢.

[解决办法]
#!/bin/sh

#first
#This file looks through all the files in the current
#directory for the string POSIX,and then prints the names of
#those files to the standard output.

for file in *; do
if grep -q POSIX "$file"; then
echo "$file"
fi
done

exit 0

读书人网 >UNIXLINUX

热点推荐