| Operator | True if... |
|---|---|
| str1 = str2[4] | str1 matches str2 |
| str1 != str2 | str1 does not match str2 |
| str1 < str2 | str1 is less than str2 |
| str1 > str2 | str1 is greater than str2 |
| -n str1 | str1 is not null (has length greater than 0) |
| -z str1 | str1 is null (has length 0) |
2012年8月28日火曜日
5.1.4.1. String comparison
5.1.4.2. File attribute checking
| Operator | True if... |
|---|---|
| -a file | file exists |
| -d file | file exists and is a directory |
| -e file | file exists; same as - a |
| -f file | file exists and is a regular file (i.e., not a directory or other special type of file) |
| -r file | You have read permission on file |
| -s file | file exists and is not empty |
| -w file | You have write permission on file |
| -x file | You have execute permission on file, or directory search permission if it is a directory |
| -N file | file was modified since it was last read |
| -O file | You own file |
| -G file | file 's group ID matches yours (or one of yours, if you are in multiple groups) |
| file1 -nt file2 | file1 is newer than file2 [6] |
| file1 -ot file2 | file1 is older than file2 |
$* and $@
"$*" is a single string that consists of all of the positional parameters, separated by the first character in the value of the environment variable IFS (internal field separator), which is a space, TAB, and NEWLINE by default. On the other hand, "$@" is equal to "$1" "$2"... "$ N", where N is the number of positional parameters. That is, it's equal to N separate double-quoted strings, which are separated by spaces. If there are no positional parameters, "$@" expands to nothing. We'll explore the ramifications of this difference in a little while.
5.2. for
for x := 1 to 10 do
begin
statements...
end
for name [in list ]
do
statements that can use
$name...
done
5.1.5. Integer Conditionals
2012年8月27日月曜日
${...}, $(...)
${...}: String Operator
- String Substitution
- String Pattern Matching
- String Length
Here are some simple examples:
If you want to edit (with vi) every chapter of your book on bash that has the phrase "command substitution," assuming that your chapter files all begin with ch, you could type:vi $(grep -l 'command substitution' ch*)
登録:
投稿 (Atom)