Shell Scripting Tutorial-2: Shell, Kernel, Terminal & More

孔宇
2023-12-01

cal

cal 7 2006

date

[root@usdalwm9 ~]# date '+DATE:%m-%y%nTIME:%H:%M:%S'
DATE:11-13
TIME:04:49:30

[root@usdalwm9 ~]# a=3.5
[root@usdalwm9 ~]# a=11.4
[root@usdalwm9 ~]# expr $a / $b|bc
expr: non-numeric argument
[root@usdalwm9 ~]# expr $a/$b|bc
3
[root@usdalwm9 ~]# expr $a/$b
11.4/3
[root@usdalwm9 ~]# expr $a/$b|bc
3
[root@usdalwm9 ~]# expr $a + $b
expr: non-numeric argument
[root@usdalwm9 ~]# expr $a + $b|bc
expr: non-numeric argument
[root@usdalwm9 ~]# expr $a+$b|bc
14.4
[root@usdalwm9 ~]# a=4
[root@usdalwm9 ~]# expr $a + $b
7
[root@usdalwm9 ~]# expr $a+$b
4+3

for word in str

do

done

util []

do

done

while []

do

done

 

 

 

[root@usdalwm9 ~]# sh ct.sh
Enter a filename
test
NUMBER of LInes:14
NUMBER of words:17
[root@usdalwm9 ~]# cat ct.sh
umask 0022
echo "Enter a filename"
read fname
terminal=`tty`
exec < $fname

nol=0

now=0

while read line
do

        nol=`expr $nol + 1`
        set $line
        now=`expr $now + $#`
done

echo "NUMBER of LInes:$nol"
echo "NUMBER of words:$now"

exec <$terminal

case $var in [a-z]*|[678]* do;; [A..Z] do;; ?) do ;; esac
 
[root@usdalwm9 ~]# seq 1 3
1
2
3
[root@usdalwm9 ~]# seq 1 3 6
1
4
[root@usdalwm9 ~]# seq 0 2 10
0
2
4
6
8
10
[root@usdalwm9 ~]# seq 0 2 4
0
2
4
[root@usdalwm9 ~]# seq 1 3
1
2
3
[root@usdalwm9 ~]# echo {1..c}
{1..c}
[root@usdalwm9 ~]# echo {a..c}
a b c
[root@usdalwm9 ~]# mkdir -p test/{1..2}/{1..2}
mkdir: cannot create directory `test': Not a directory
mkdir: cannot create directory `test': Not a directory
mkdir: cannot create directory `test': Not a directory
mkdir: cannot create directory `test': Not a directory
[root@usdalwm9 ~]# mkdir -p ./{1..2}/{1..2}
mkdir: cannot create directory `./1': Not a directory
mkdir: cannot create directory `./1': Not a directory
 
[root@usdalwm9 ~]# for i in {3..1};do echo $i ;done
3
2
1
 
 
 
 
 
 
 
 
 
 
 

 类似资料: