linux下的文件服务器[ftp(ftp/tftp)、 Samba、NFS服务器](转)

(转自:http://www.xuelang.net/webInfo/xuelang/it/Linux/LinKnw/0956534300.htm

linux下的文件服务器

作者:田逸(sery@163.com) 《网管员世界》2006年第一期

对于一个真实的运行环境而言,配置和启用文件服务器都是很有必要的。把重要的数据集中存储和管理,其安全性显然比分布存储要可靠得多。为此,建议系统管理员配制和启用文件服务器作为基本的管理策略。

根据使用的方式来看,可以分为3种类别的文件服务器:ftp服务器(ftp/tftp)、 Samba服务器、NFS服务器。ftp的客户可以是任意平台,samba是专门针对windows客户,而NFS则是面向linux/unix用户的。下面是三种服务器的对比情况:

服务器名称     用户客户端平台     使用范围     服务端口

FTP     Windows/linux/unix/macOS等     发布网站,文件共享     Tcp/21

Samba     Windows     文件共享(网上邻居)     Tcp/445,tcp/139

NFS     Linux/unix     网站发布,文件共享(mount)     Tcp/2049

接下来我们就逐个来配置和运行这些服务器。

NFS服务器

  NFS是SUN Microsystem公司开发的网络文件系统,它是一种基于远程过程调用(RPC)的分布式文件系统架构。与Samba相比较,NFS的数据吞吐能力更强。

1、     用命令 # rpm –qa | grep nfs检查软件包NFS是否安装 ,如果输出没有输出,表明没有被安装,请自行安装之。

2、     配置NFS服务器。用任何文本编辑器配置文件/etc/exports,来确定需要给客户共享的目录。它的基本格式为 Directory   Host(options) # comments ,这3个字段/列要在一行,directory与host(options)之间要有间隙,# comments 可有可无。主机选项主要是给与挂接用户什么样的权限。目录directory表示要共享出去的目录,值得注意的是,在启用NFS服务以前,系统管理员应该仔细一些,比如不小心共享了根目录/,并且给与用户读写权限,这是十分糟糕的问题。因此,尽可能少的共享目录和赋予较小的访问权限。主机名host是一个很灵活的项目,可以是单个的主机名称(由/etc/hosts得到),主机ip地址,由域名服务器解析的主机名称,IP网络---网络号和子网掩码中间用 “/”连接,NIC等。下面列举一个例子。

/home/sery     sery(r,w) #把目录/home/sery共享给主机sery,并且主机对目录#/home/sery有读写权限

/tmp       192.168.100.18(ro) #主机192.168.100.18对目录/tmp具备只读共#享权限

/media/cdrom   192.168.100.0/255.255.255.0(r,o) #整个网络有读取挂接在NFS 

#服务器上的光驱光盘的读取权限

3、     启用NFS服务。分两步:首先启用portmap,然后启用NFS服务。# service portmap start;

# service nfs start。其中portmap的功能是启用远程过程调用,有时启用NFS不能成功,不妨检查一下portmap服务是否启动(# ps aux | grep portmap)。

4、     在客户端挂接NFS共享出来的目录。先在客户端创建一个挂接点,如 # mkdir /mnt/nfs ,而后使用命令把nfs服务器共享出来的目录挂接上,以第2步那个共享为例,我们挂接目录 /tmp , # mount –t nfs 192.168.100.100:/tmp /mnt/nfs //假定nfs服务器的ip地址是192.168.100.100。

5、     访问NFS共享资源。接上步,改变文件目录 # cd /mnt/nfs就方便地实现了对nfs服务器目录/tmp的远程访问。

6、     卸载NFS文件系统。在客户端执行命令 # umount /mnt/nfs 就卸下了第4步挂接的NFS文件系统。

7、     其他事项。前面我们描述了在客户段用手工挂接NFS文件系统的操作,有的场合可能需要自动实现对NFS的挂接操作;修改文件/etc/fstab,把挂接项插入进去就可以了。对一个有较多连接的NFS服务器而言,有这样一个问题---用户在使用完挂接的文件系统后,并不会总记得卸载掉NFS挂接,这必然会增大NFS服务器的维护工作量以及白白占用有限的系统和网络资源;解决这个问题的办法是使用自动挂接器(automounter)。关于自动挂接器属于性能调优的范畴,在此不做描述。

Samba服务器

  这个世界既非只有linux/unix,也不是由microsoft windows 独霸天下的格局。也许出于linux/unix与windows既竞争又共存的事实,人们开发了 linux给windows用户提供文件共享的工具Samba,这应该算得上linux的开放精神吧!

1、     检查是否安装samba软件包。# rpm –qa | grep smb ,如果没有则自行安装samba。

2、     修改配置文件/etc/samba/smb.conf。早期的linux版本的配置文件smb.conf的安全选项“security=share”,这个默认值是个安全隐患,不过现在流行的linux版本的安全选项的默认值是“security=user”。如果只想用户对他的目录拥有只读权限,就把选项“writeable=yes”改成“read only=yes”。其他的选项根据自己的要求更改即可。对于一般的应用而言,基本上不用修改这个文件。

3、     添加系统账户。由于smb的访问是使用系统账号进行的,因此添加账号是必不可少的。这个比较简单,用命令 # useradd sery , # passwd sery,就可以依次添加若干系统账号。

4、     建立Samba用户密码文件。虽然samba的用户是系统用户,但出于安全考虑,samba用户的密码并非创建系统用户时设定的用户密码。为了生成smb所需的密码,应该进行下面的操作:

# cat /etc/passwd | mksmbpasswd.sh > /etc/samba/smbpasswd

# smbpasswd sery   //为系统用户设置smb口令

# chown root.root /etc/samba/smbpasswd

# chmod 600 /etc/samba/smbpasswd   //不准别的用户访问

5、     启用Samba服务器。我比较喜欢用 # service smb start 这种方式。

6、     检查服务是否正常启动。# service smb status 或者 # ps aux | grep smb。

7、     windows客户端访问 Samba服务器共享目录。在windows环境下,右键点击“网上邻居”图标,然后左击“搜索计算机”,把Samba服务器的IP地址填写在“计算机名”搜索栏,点击立即搜索。找到后双击图标,然后输入在Samba服务器上预先设定的用户名和密码,就能合法访问Samba服务器设定的共享资源。为了方便使用,可以把Samba服务器提供的共享目录映射成本地驱动器。

8、     其他。上述配置的samba服务器,用户的访问共享目录是系统账号的主目录。要想把共享目录设置到其他位置,修改Samba 的配置文件/etc/samba/smb.conf文件即可。

FTP服务器

  在linux 环境下,有三个主要的FTP服务器:vsftpd、proftpd和wu-ftpd。因为安全方面的原因,vsftpd目前已经牢牢的占据了主导地位。从字面上我们就可以理解vsftpd所具备的主要特征---very secure(非常安全之ftp)。资料表明:1、使用ASCII方式下载文件,在1G以太网上的下载速度可以达到86M/s。2、vsftpd可以支持 15000个并发用户的访问。

1、     检查是否安装vsftp包。# rpm –qa | grep vsftpd。如果没有则安装它。

2、     修改配置文件。Vsftpd的配置文件为/etc/vsftpd/vsftpd.conf,如果不打算提供匿名访问的话,需要修改配置文件 /etc/vsftpd/vsftpd.conf的项“anonymous_enable=Yes”为“anonymous_enable=No”。

3、     启用vsftpd服务。#service vsftpd start。

4、     客户端连接访问。可以是专用的ftp客户端工具,也可以使用浏览器。用工具访问vsftpd服务器的速度要比用浏览器快很多。

5、     vsftpd服务器的用户。Vsftpd服务器支持三种类型的拥护:本地用户(拥有系统账号)、虚拟用户(guest)、匿名账号;系统管理员应该根据安全需求来确定vsftpd服务器的用户访问策略。

TFTP服务器

  Tftp服务器主要用于远程系统引导或远程备份象CISCO这样的网络设备的配置文件,例如tftp服务器与DHCP、FTP服务器相配合,就可以成为一组linux安装服务器,以利于进行大规模的网络安装linux操作系统。

  与上文提及的几种服务器不同,tftp服务器是由超级守护进程xinetd运行的。这使的tftp服务器的配置操作比独立运行守护进程的服务器(如 vsftpd)简单很多。一般情况下,只要修改文件/etc/xinetd.d/tftp,把“disable =yes” 改成 “disable =no”,而后保存重新启动超级守护进程xinetd , # service xinetd restart 。

  通过上面的实践,尽管我们已经能够顺利的完成各种文件服务器的搭建和运行,也基本上可以满足基本的用户服务需求,也许在实际的工作中,可能有更多的性能或安全要求。一个明显的例子就是,如果一个用户的服务器使用的磁盘空间没有做任何限制,那么他完全有可能把他从internet下载的连续剧上传到他自己的文件服务器目录,从而把有限空间的硬盘塞满。另外一个就是目录和文件的权限问题,特别是以本地账号(系统账号)访问文件服务器的情况,如果授权不当,将给系统管理带来极大的麻烦。

  Linux所倡导的自由精神也同样在这些服务器的配置操作中得以体现。可以通过修改这些服务器的配置文件来满足特定的需求,而且这些修改是非常灵活的。比如vsftpd服务器的配置文件/etc/vsftpd/vsftpd.conf就有很多项目可以修改。

  附表:几种文件服务器的维护

服务器名称

    启动脚本

    守护进程

    配置文件

NFS     /etc/init.d/nfs

/etc/init.d/nfslock     /usr/sbin/rpc.nfsd

/usr/sbin/rpc.mountd     /etc/exports

Samba     /etc/init.d/smb

/etc/init.d/winbind     /usr/sbin/smbd

/usr/sbin/nmbd     /etc/samba/smb.conf

vsftpd     /etc/xinetd.d/vsftpd     /usr/sbin/vsftpd     /etc/vsftpd/vsftpd.conf

                   --转载完

7.1. Test Constructs

1、command &>filename redirects both the stdout and the stderr of command to

    filename.


       1 if cmp a b &> /dev/null  # Suppress output.

       2 then echo "Files a and b are identical."

       3 else echo "Files a and b differ."

       4 fi

2、|

    pipe. Passes the output of previous command to the input of the next one,

    or to the shell. This is a method of chaining commands together.


      12 word=Linux

      13 letter_sequence=inu

      14 if echo "$word" | grep -q "$letter_sequence"

      15 # The "-q" option to grep suppresses output.

      16 then

      17   echo "$letter_sequence found in $word"

      18 else

      19   echo "$letter_sequence not found in $word"

      20 fi

3、这个嵌套结构有点怪,还有(())和[[]]的有什么区别?

  它的结构是:

  if ()

    if()

    then()

    else()

    endif

  then()

  endif

  总觉得不如这样:

  if ()

  then

    if()

    then()

    else()

    endif

    ()

  endif

 · An if/then construct can contain nested comparisons and tests.


       1 if echo "Next *if* is part of the comparison for the first *if*."

       2

       3   if [[ $comparison = "integer" ]]

       4     then (( a < b ))

       5   else

       6     [[ $a < $b ]]

       7   fi

       8

       9 then

      10   echo '$a is less than $b'

      11 fi

4、example 7-1

bash里面的测试命令真是多呀?test [] [[]] (()) let ... ,快昏了。

[0]和[1]和[-1]的测试结果都是true,不懂?

[ -n "$xyz" ] 里面的-n什么作用?(

[]就是test命令

在man test中查到如下:

[-n] STRING

              the length of STRING is nonzero

)


#!/bin/bash

#  Tip:

#  If you're unsure of how a certain condition would evaluate,

#+ test it in an if-test.

echo

echo "Testing \"0\""

if [ 0 ]      # zero

then

  echo "0 is true."

else

  echo "0 is false."

fi            # 0 is true.

echo

echo "Testing \"1\""

if [ 1 ]      # one

then

  echo "1 is true."

else

  echo "1 is false."

fi            # 1 is true.

echo

echo "Testing \"-1\""

if [ -1 ]     # minus one

then

  echo "-1 is true."

else

  echo "-1 is false."

fi            # -1 is true.

echo

echo "Testing \"NULL\""

if [ ]        # NULL (empty condition)

then

  echo "NULL is true."

else

  echo "NULL is false."

fi            # NULL is false.

echo

echo "Testing \"xyz\""

if [ xyz ]    # string

then

  echo "Random string is true."

else

  echo "Random string is false."

fi            # Random string is true.

echo

echo "Testing \"\$xyz\""

if [ $xyz ]   # Tests if $xyz is null, but...

              # it's only an uninitialized variable.

then

  echo "Uninitialized variable is true."

else

  echo "Uninitialized variable is false."

fi            # Uninitialized variable is false.

echo

echo "Testing \"-n \$xyz\""

if [ -n "$xyz" ]            # More pedantically correct.

then

  echo "Uninitialized variable is true."

else

  echo "Uninitialized variable is false."

fi            # Uninitialized variable is false.

echo

xyz=          # Initialized, but set to null value.

echo "Testing \"-n \$xyz\""

if [ -n "$xyz" ]

then

  echo "Null variable is true."

else

  echo "Null variable is false."

fi            # Null variable is false.

echo

# When is "false" true?

echo "Testing \"false\""

if [ "false" ]              #  It seems that "false" is just a string.

then

  echo "\"false\" is true." #+ and it tests true.

else

  echo "\"false\" is false."

fi            # "false" is true.

echo

echo "Testing \"\$false\""  # Again, uninitialized variable.

if [ "$false" ]

then

  echo "\"\$false\" is true."

else

  echo "\"\$false\" is false."

fi            # "$false" is false.

              # Now, we get the expected result.

#  What would happen if we tested the uninitialized variable "$true"?

echo

exit 0

5、[[]]比[]更加有用?


The [[ ]] construct is the more versatile Bash version of [ ]. This is the

extended test command, adopted from ksh88.

...

Tip Using the [[ ... ]] test construct, rather than [ ... ] can prevent many

    logic errors in scripts. For example, the &&, ||, <, and > operators work

    within a [[ ]] test, despite giving an error within a [ ] construct.

6、

Following an if, neither the test command nor the test brackets ( [ ] or

     [[ ]] ) are strictly necessary.

例如:


[mdx@localhost abs-exercises]$ if dir; then echo "dir success"; else echo

"fail" ; fi

3    ch4-2.txt  ch7-0-1.sh  ctrl-m.sh  ex2-2.sh  ex4-5.sh  ex5-2.sh  ex7-1.sh

3]]  ch5-2.txt  ch7-1.txt   env.txt    ex2-3.sh  ex4-6.sh  ex6-1.sh  plan2.txt

b]]  ch6.txt    ctrl-h.sh   ex2-1.sh   ex4-2.sh  ex4-7.sh  ex7-0.sh  plan.txt

dir success

[mdx@localhost abs-exercises]$

[mdx@localhost abs-exercises]$ if Dir; then echo "dir success"; else echo

"fail" ; fi

bash: Dir: command not found

fail

[mdx@localhost abs-exercises]$

7、(( 1 / 0 )) 2>/dev/null不懂?


  29 (( 1 / 0 )) 2>/dev/null                          # Illegal division by 0.

  30 #           ^^^^^^^^^^^

  31 echo "Exit status of \"(( 1 / 0 ))\" is $?."     # 1

  32

  33 # What effect does the "2>/dev/null" have?

  34 # What would happen if it were removed?

  35 # Try removing it, then rerunning the script.

8、英语疑问:

1)The (( ... )) and let ... constructs also return an exit status of 0 if the

    arithmetic expressions they evaluate expand to a non-zero value.

2)This is in marked contrast to using the test and [ ] constructs previously discussed.

5.2. Escaping

1、Example 5-2(怎么样才能显示下面这个 $escape ?)

 


      54 escape=$'\033'                    # 033 is octal for escape.

      55 echo "\"escape\" echoes as $escape"

      56 #                                   no visible output.

 

2、echo -e的用法:


[mdx@localhost abs-exercises]$ echo "\n"

\n

[mdx@localhost abs-exercises]$ echo -e "\n"

[mdx@localhost abs-exercises]$

[mdx@localhost abs-exercises]$ echo "\\"

\

[mdx@localhost abs-exercises]$ echo -e "\\"

\

[mdx@localhost abs-exercises]$ echo -e '\\'

\

[mdx@localhost abs-exercises]$ echo  '\\'

\\

3、可是说是一些非常烦人的用法,不用去记它,平常也用不着吧。

Note The behavior of \ depends on whether it is itself escaped, quoted, or

     appearing within command substitution or a here document.


        1                       #  Simple escaping and quoting

        2 echo \z               #  z

        3 echo \\z              # \z

        4 echo '\z'             # \z

        5 echo '\\z'            # \\z

        6 echo "\z"             # \z

        7 echo "\\z"            # \z

        8

        9                       #  Command substitution

       10 echo `echo \z`        #  z

       11 echo `echo \\z`       #  z

       12 echo `echo \\\z`      # \z

       13 echo `echo \\\\z`     # \z

       14 echo `echo \\\\\\z`   # \z

       15 echo `echo \\\\\\\z`  # \\z

       16 echo `echo "\z"`      # \z

       17 echo `echo "\\z"`     # \z

       18

       19                       # Here document

       20 cat <<EOF

       21 \z

       22 EOF                   # \z

       23

       24 cat <<EOF

       25 \\z

       26 EOF                   # \z

       27

       28 # These examples supplied by St?phane Chazelas.

4、\可以起到续行符的作用,文中的叙述:

The escape also provides a means of writing a multi-line command. Normally,

each separate line constitutes a different command, but an escape at the end of

a line escapes the newline character, and the command sequence continues on to

the next line.

例如:下面的dir这个命令被分成3行来写,每行一个字符:)


[mdx@localhost abs-exercises]$ d\

> i\

> r

ch4-2.txt  ctrl-h.sh  ex2-1.sh  ex2-3.sh  ex4-5.sh  ex4-7.sh  plan2.txt

ch5-2.txt  ctrl-m.sh  ex2-2.sh  ex4-2.sh  ex4-6.sh  ex5-2.sh  plan.txt

[mdx@localhost abs-exercises]$ dir

ch4-2.txt  ctrl-h.sh  ex2-1.sh  ex2-3.sh  ex4-5.sh  ex4-7.sh  plan2.txt

ch5-2.txt  ctrl-m.sh  ex2-2.sh  ex4-2.sh  ex4-6.sh  ex5-2.sh  plan.txt

Chapter 5. Quoting

Chapter 5. Quoting

1、那个IFS是什么意思?

Example 5-1. Echoing Weird Variables


   1 #!/bin/bash

   2 # weirdvars.sh: Echoing weird variables.

   3

   4 var="'(]\\{}\$\""

   5 echo $var        # '(]\{}$"

   6 echo "$var"      # '(]\{}$"     Doesn't make a difference.

   7

   8 echo

   9

  10 IFS='\'

  11 echo $var        # '(] {}$"     \ converted to space. Why?

  12 echo "$var"      # '(]\{}$"

  13

  14 # Examples above supplied by Stephane Chazelas.

  15

  16 exit 0

2、


[mdx@localhost mdx]$ echo '\''

>

>

>

...

(回车就显示>,永远不会出现',除非'没有在两个'之中)

Since even the escape character (\) gets a literal interpretation within single quotes, trying to enclose a single quote within single quotes will not yield the expected result.


   1 echo "Why can't I write 's between single quotes"

   2

   3 echo

   4

   5 # The roundabout method.

   6 echo 'Why can'\''t I write '"'"'s between single quotes'

   7 #    |-------|  |----------|   |-----------------------|

   8 # Three single-quoted strings, with escaped and quoted single quotes between.

   9

  10 # This example courtesy of Stéphane Chazelas.

3、太令人难以把握了,没有规律吗?

Of more concern is the inconsistent behavior of "\" within double quotes.


 bash$ echo hello\!

 hello!

 

 

 bash$ echo "hello\!"

 hello\!

 

 

 

 

 bash$ echo -e x\ty

 xty

 

 

 bash$ echo -e "x\ty"

 x       y

       

4、生词:

Quoting can also suppress echo's  "appetite" for newlines.

Weird

discrete

4.3. Bash Variables Are Untyped, 4.4. Special Variable Types

1、

http://www.linuxsir.org/main/doc/abs/HTML/untyped.html

4.3. Bash Variables Are Untyped

Example 4-4. Integer or string?

  20 c=BB34

  21 echo "c = $c"            # c = BB34

  22 d=${c/BB/23}             # Substitute "23" for "BB".

  23                          # This makes $d an integer.

  24 echo "d = $d"            # d = 2334

2、

http://www.linuxsir.org/main/doc/abs/HTML/othertypesv.html

The space allotted to the environment is limited. Creating too many environmental variables or ones that use up excessive space may cause problems.

 bash$ eval "`seq 10000 | sed -e 's/.*/export var&=ZZZZZZZZZZZZZZ/'`"

 

 bash$ du

 bash: /usr/bin/du: Argument list too long

3、

命令:basename(# Strips out path name info (see 'basename'))

[mdx@localhost abs-exercises]$ basename /home/mdx/abs-guide-3.7/ex15.sh

ex15.sh

4、比较:


16 if [ -n "$1" ]              # Tested variable is quoted.

  17 then

  18  echo "Parameter #1 is $1"  # Need quotes to escape #

  19 fi

5、得到最后一个参数:


   1 args=$#           # Number of args passed.

   2 lastarg=${!args}

   3 # Or:       lastarg=${!#}

   4 #           (Thanks, Chris Monson.)

   5 # Note that lastarg=${!$#} doesn't work.

6、待查

If a script expects a command line parameter but is invoked without one, this may cause a null variable assignment, generally an undesirable result. One way to prevent this is to append an extra character to both sides of the assignment statement using the expected positional parameter.


   1 variable1_=$1_  # Rather than variable1=$1

   2 # This will prevent an error, even if positional parameter is absent.

   3

   4 critical_argument01=$variable1_

   5

   6 # The extra character can be stripped off later, like so.

   7 variable1=${variable1_/_/}

   8 # Side effects only if $variable1_ begins with an underscore.

   9 # This uses one of the parameter substitution templates discussed later.

  10 # (Leaving out the replacement pattern results in a deletion.)

  11

  12 #  A more straightforward way of dealing with this is

  13 #+ to simply test whether expected positional parameters have been passed.

  14 if [ -z $1 ]

  15 then

  16   exit $E_MISSING_POS_PARAM

  17 fi

  18

  19

  20 #  However, as Fabian Kreutz points out,

  21 #+ the above method may have unexpected side-effects.

  22 #  A better method is parameter substitution:

  23 #         ${1:-$DefaultVal}

  24 #  See the "Parameter Substition" section

  25 #+ in the "Variables Revisited" chapter.

7、在Example 4-6. wh, whois domain name lookup中,域名查询的服务器是无效的,可以换成:"wh-inn" ) whois $1@whois.internic.net;;

8、生词:

positional

notch

4.2. Variable Assignment(echo -n,!,$())

1、echo -n的作用简单的说就是不换行,像java中的System.out.print("something");


    19 # In a 'for' loop (really, a type of disguised assignment):

    20 echo -n "Values of \"a\" in the loop are: "

    21 for a in 7 8 9 11

    22 do

    23   echo -n "$a "

    24 done

结果:Values of "a" in the loop are: 7 8 9 11

2、

下面这段的“!”不懂:

  


    10 a=`echo Hello!`   # Assigns result of 'echo' command to 'a'

    11 echo $a

    12 #  Note that including an exclamation mark (!) within a

    13 #+ command substitution construct #+ will not work from the command line,    14 #+ since this triggers the Bash "history mechanism."

    15 #  Inside a script, however, the history functions are disabled.

 

3、``相当于$()


     2 R=$(cat /etc/redhat-release)

4、英语生词:

disguised

naked

trailing

4.1. Variable Substitution(双引号,一行赋多值,未初始化变量)�

1、双引号内的变量可以保留变量值当中的超过一个空格的空格:

(abs-guide-3.7/HTML/variables.html#VARSUBN)

Example 4-1. Variable assignment and substitution


  33 hello="A B  C   D"

  34 echo $hello   # A B C D

  35 echo "$hello" # A B  C   D

  36 # As you see, echo $hello   and   echo "$hello"   give different results.

  37 #                                      ^      ^

  38 # Quoting a variable preserves whitespace.

2、可以在一行中对多个变量赋值,但是在有可能引起版本兼容性问题:

(abs-guide-3.7/HTML/variables.html#VARSUBN)

Example 4-1. Variable assignment and substitution


  57 #  It is permissible to set multiple variables on the same line,

  58 #+ if separated by white space.

  59 #  Caution, this may reduce legibility, and may not be portable.

  60

  61 var1=21  var2=22  var3=$V3

  62 echo

  63 echo "var1=$var1   var2=$var2   var3=$var3"

  64

  65 # May cause problems with older versions of "sh".

3、在没有初始化的变量上进行算术运算不是非法的,当作是"0",但是在有可能引起版本兼容性问题:

(abs-guide-3.7/HTML/variables.html#VARSUBN)


An uninitialized variable has a "null" value - no assigned value at all (not zero!). Using a variable before assigning a value to it will usually cause problems.

It is nevertheless possible to perform arithmetic operations on an uninitialized variable.

   1 echo "$uninitialized"                                # (blank line)

   2 let "uninitialized += 5"                             # Add 5 to it.

   3 echo "$uninitialized"                                # 5

   4

   5 #  Conclusion:

   6 #  An uninitialized variable has no value, however

   7 #+ it acts as if it were 0 in an arithmetic operation.

   8 #  This is undocumented (and probably non-portable) behavior.

我的redhat linux9.0的/etc/fstab


LABEL=/                 /                       ext3    defaults        1 1

/dev/hdc5              /boot                   ext2    defaults        1 2

none                    /dev/pts                devpts  gid=5,mode=620  0 0

none                    /proc                   proc    defaults        0 0

none                    /dev/shm                tmpfs   defaults        0 0

/dev/hdc7              /usr/local              ext3    defaults        1 2

/dev/hdc9               swap                    swap    defaults        0 0

/dev/hdc12              /home                   ext3    defaults        1 2

/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0

/dev/cdrom              /mnt/cdrom              udf,iso9660 noauto,owner,kudzu,ro 0 0

我因为分区的时候有几个分区没有指定LABEL,所以只能以设备名来装载。这样,当把硬盘从主盘换到从盘,或者从IDE0换到IDE1时,设备名就变了,这样就必须修改这个文件才能正常使用。

也不知道怎么样在已使用分区上添加LABEL?

Ctl-M(Carriage return.)(不懂)

read echo >$2 不懂

(http://www.linuxsir.org/main/doc/abs/HTML/special-chars.html)

Ctl-M

Carriage return.

   1 #!/bin/bash

   2 # Thank you, Lee Maschmeyer, for this example.

   3

   4 read -n 1 -s -p $'Control-M leaves cursor at beginning of this line. Press Enter. \x0d'

   5                                   # Of course, '0d' is the hex equivalent of Control-M.

   6 echo >&2   #  The '-s' makes anything typed silent,

   7            #+ so it is necessary to go to new line explicitly.

   8

   9 read -n 1 -s -p $'Control-J leaves cursor on next line. \x0a'

  10            #  '0a' is the hex equivalent of Control-J, linefeed.

  11 echo >&2

  12

  13 ###

  14

  15 read -n 1 -s -p $'And Control-K\x0bgoes straight down.'

  16 echo >&2   #  Control-K is vertical tab.

  17

  18 # A better example of the effect of a vertical tab is:

  19

  20 var=$'\x0aThis is the bottom line\x0bThis is the top line\x0a'

  21 echo "$var"

  22 #  This works the same way as the above example. However:

  23 echo "$var" | col

  24 #  This causes the right end of the line to be higher than the left end.

  25 #  It also explains why we started and ended with a line feed --

  26 #+ to avoid a garbled screen.

  27

  28 # As Lee Maschmeyer explains:

  29 # --------------------------

  30 #  In the [first vertical tab example] . . . the vertical tab

  31 #+ makes the printing go straight down without a carriage return.

  32 #  This is true only on devices, such as the Linux console,

  33 #+ that can't go "backward."

  34 #  The real purpose of VT is to go straight UP, not down.

  35 #  It can be used to print superscripts on a printer.

  36 #  The col utility can be used to emulate the proper behavior of VT.

  37

  38 exit 0