$ for file in * > do > if grep -l POSIX $file > then > more $file > fi > done posix This is a file with POSIX in it - treat it well $
$ 就變成 >。
"*" ,用來代表任何吻合的字串。
grep -l POSIX:表示若檔案中包含字串 POSIX 則顯示檔名,而不顯示內容。
#!/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
[csie@localhost csie]$ file sh02.sh sh02.sh: Bourne shell script text executable [csie@localhost csie]$ file /bin/bash /bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), stripped
$ /bin/sh sh02.sh
$ chmod +x sh02.sh $ sh02.sh bash: sh02.sh: command not found $ ./sh02.sh
練習題
[Enter] 符號
\[Enter]
# 後面的字,全部被視為註解
#!/bin/bash ,代表意義為何?
2017-06-14