Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 UNIX 的新手 我正在尝试编写一个脚本,它将在某个单词上 grep 并打印找到它的行和文件,如果它可用,如果它没有找到,则回显不可用
这是我的代码
#!/bin/csh foreach file(`cat file1`) set a=`echo $file | grep -n "ok" ` if(" $a" -ne 0 ) then echo "$a" | echo $file else echo "not found" endif end
正确的语法是
#!/bin/csh foreach file(`cat file1`) set a=`echo $file | grep -n "ok" ` if(" $a" != " " ) then echo "$a" echo $file else echo "not found" endif end