4
shell
SHELL
, shell (shell script "" " "). , . (, -, ).
shell , "Hello world!" , , hello.sh. :
echo Hello world!
, . , shell , , <Enter>, ?
shell shell . :
sh hello.sh
1)
,
name=value
name value. , . value . ( ) $ ${name}. , , ( )
2)
. QNX shell :
- ;
- ;
- (, ..1))
- , shell shell. $ 0-9 .. $1- ; $2 - , ..
set ( shell).
shell . :
$@ - , , , ;
$* - , , , ;
|
|
$# - ;
$? - (0 );
$$ - shell;
$! - ;
$0 - shell ( shell).
set
set [option] [-o option name]... [argument...]
set [option] [+o option name]... [argument...]
set --
set argument. set-- .
SHELL
. , , , , . , ( ) .
1.2.1. .
/.
1.2.2. .
"|", . , , .
1.2.3. .
";" "&" "&&" "||" . :
; - ;
& - ; ;
&& - "&&" , (""); || - "||" , "||", ("").
1.2.4. .
; "$":
$(command)
1.2.5. .
"*" "?" []. , .
* - ;
? - ;
[...]
.
, [a-c] - a-c;
"!".
[!abc] - a b c.
1.2.1.
test.
test expression [expression]
test "" "". if, while.
():
-r file - ;
-w file - ;
|
|
-x file - ;
-f file - ;
-d file - ;
file1 -ot file2 - 1 2;
string - ;
string1 = string2 - 1 2;
string1!= string2 - 2 2;
num1 -eq num2 - 1 2;
num1 -ne num2 - 1 2;
num1 -ge num2 - 1 2;
num1 -gt num2 - 1 2;
num1 -le num2 - 1 2;
num1 -lt num2 - 1 2
:
expr -o expr - "";
expr -a expr - "";
!expr - ;
(expr) - .
read.
read [-r] var...
read (), . var, var .
-r "\" , , escape-.
shell , ( expr) , .
2.1.
var=abcd
xy=$var+4
xyz=${xy}4
var2=ab c de
y=$var2-5
print $var $xy $xyz $y
print echo.
read r t y
1 2 3 4
print $r $t $y
print $y
2.2.
set --
print $#
set a b c
print $#
print $@ $*
print $0
print $?
print $$
ls abc
print $?
2.3.
.
print $(date)
print $(ls)
cd /home/g( )
ls
rm d[!i]*; ls
rm e?; ls
2.4.
:
test 3 -gt 2 && use ls
test 3 -lt 2 && use ls
test 3 -lt 2 || use ls
test ab3 = ab2 || use ls
test ab3!= ab2 || use ls
-r file.
2.5.
use expr
x=50
y=40
a=$(expr $x + $y); print $a
a=$(expr $x / $y); print $a
a=$(expr $x - $y); print $a
a=$(expr $x * $y); print $a
3.
1. .
2. .
3. .
4. 2.1-2.5.
5
shell