- 博客(24)
- 资源 (1)
- 收藏
- 关注
转载 expr的使用
#!/bin/bash# Demonstrating some of the uses of 'expr'# =======================================echo# Arithmetic Operators# ---------- ---------echo "Arithmetic Operators"echoa=`expr 5 + 3`
2012-10-31 21:49:39 20894
原创 linux eval命令参数及用法详解--linux重新运算求出参数的内容
#!/bin/bash# Exercising "eval" ...y=`eval ls -l /home` # Similar to y=`ls -l`echo $y #+ but linefeeds removed because "echoed" variable is unquoted.echoecho "$y" # Linefeeds pre
2012-10-31 21:35:17 76854
转载 find命令和xargs命令
能很好的用好find将是Linux工作的一大幸事,不要奢望一口气记住本文所有的方法,要慢慢的去尝试和领会这些用法的精妙和合理之处,到了一定时候自然会记住很多,能够举一反三将是最大的收获!1.find由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时间来了解一下。即使系统中含有网络文件系统( N F S ),find命令在该文件系统中同样有效,只你具有相应的权限。
2012-10-30 21:24:12 73730
原创 写logfile (ex41.sh)
#!/bin/bash# Generates a log file in current directory# from the tail end of /var/log/messages.# Note: /var/log/messages must be world readable# if this script invoked by an ordinary user.#
2012-10-30 20:32:24 54067
原创 root账户的判定
#!/bin/bashROOT_UID=0 # Only users with $UID 0 have root privileges.E_NOTROOT=65E_NOPARAMS=66if [ "$UID" -ne "$ROOT_UID" ]then echo "Must be root to run this script." # "Run along kid, it
2012-10-30 15:55:12 50192
原创 load一个数据文件
#!/bin/bash. data-file # Load a data file.# Same effect as "source data-file", but more portable.# The file "data-file" must be present in current working directory,#+ since it is referred to
2012-10-30 15:34:36 13412
原创 pushd和popd的使用(ex37.sh)
#!/bin/bashdir1=/usr/localdir2=/var/spoolpushd $dir1# Will do an automatic 'dirs' (list directory stack to stdout).echo "Now in directory `pwd`." # Uses back-quoted 'pwd'.# Now, do some stuff
2012-10-30 15:28:18 14845
原创 read的使用 (ex36.sh)
#!/bin/bash# "Reading" variables.echo -n "Enter the value of variable 'var1': "# The -n option to echo suppresses newline.read var1# Note no '$' in front of var1, since it is being set.echo "
2012-10-30 15:19:37 11224
原创 basename和dirname的使用 (ex35.sh)
#!/bin/basha=/home/bozo/daily-journal.txtecho "Basename of /home/bozo/daily-journal.txt = `basename $a`"echo "Dirname of /home/bozo/daily-journal.txt = `dirname $a`"echoecho "My own home is `ba
2012-10-30 15:17:26 11335
原创 set的使用 (ex34.sh)
#!/bin/bash# ex34.sh# Script "set-test"# Invoke this script with three command-line parameters,# for example, "sh ex34.sh one two three".echoecho "Positional parameters before set \`uname -a\
2012-10-30 15:12:12 10191
转载 Linux getopts&shift命令浅析
在Shell命令/函数中 shift常用来获取参数值(可以突破Linux 参数值只能传入$1-$9的限制),而getopts可用来获取选项参数 对于shift,例如:#!/bin/bashusage(){ echo "usage:`basename $0` -[l|u] file [files]" >&2 exit 1 } if [ $# -eq 1 ]; then
2012-10-30 15:06:58 65297
原创 select的使用
#!/bin/bashPS3='Choose your favorite vegetable: ' # Sets the prompt string. # Otherwise it defaults to #? .echoselect vegetable in "beans" "carrots" "potat
2012-10-30 14:42:18 9201
原创 case的使用
#!/bin/bash# Testing ranges of characters.echo; echo "Hit a key, then hit return."read Keypresscase "$Keypress" in [[:lower:]] ) echo "Lowercase letter";; [[:upper:]] ) echo "Uppercase l
2012-10-30 14:14:08 7619
原创 shell中until的使用 (ex27.sh)
#!/bin/bashEND_CONDITION=enduntil [ "$var1" = "$END_CONDITION" ]# Tests condition here, at top of loop.do echo "Input variable #1 " echo "($END_CONDITION to exit)" read var1 echo "variab
2012-10-29 12:31:20 6223
原创 shell中while的使用 (ex26.sh,ex26a.sh)
#!/bin/bashecho # Equivalent to:while [ "$var1" != "end" ] # while test "$var1" != "end"do echo "Input variable #1 (end to exit) " read var1
2012-10-29 12:23:56 6075
原创 shell中for循环的使用--空list (ex23.sh)
#!/bin/bash# Invoke this script both with and without arguments,#+ and see what happens.for ado echo -n "$a "done# The 'in list' missing, therefore the loop operates on '$@'#+ (command-li
2012-10-29 11:38:06 26124
原创 shell中for循环和set的使用 (ex22a.sh)
#!/bin/bash# Planets revisited.# Associate the name of each planet with its distance from the sun.for planet in "Mercury 36" "Venus 67" "Earth 93" "Mars 142" "Jupiter 483"do set -- $planet #
2012-10-29 11:34:55 6313
原创 shell中for循环的使用 (ex22.sh)
#!/bin/bash# Listing the planets.for planet in Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Plutodo echo $planet # Each planet on a separate line.doneecho; echofor planet in "Mer
2012-10-29 11:27:37 5009
原创 shell中random的使用 (ex21.sh)
#!/bin/bash# $RANDOM returns a different random integer at each invocation.# Nominal range: 0 - 32767 (signed 16-bit integer).MAXCOUNT=10count=1echoecho "$MAXCOUNT random numbers:"echo "----
2012-10-29 11:24:25 5667
原创 declare的使用 (ex20.sh)
#!/bin/bashfunc1 (){ echo This is a function.}declare -f # Lists the function above.echodeclare -i var1 # var1 is an integer.var1=2367echo "var1 declared as $var1"var1=var1+1
2012-10-28 21:54:38 5368
原创 脚本参数中shift的使用 (ex19)
#!/bin/bash# shft.sh: Using 'shift' to step through all the positional parameters.# Name this script something like shft.sh,#+ and invoke it with some parameters.#+ For example:# sh
2012-10-28 21:36:07 3771
原创 脚本参数的使用(ex17.sh)
#!/bin/bash# Call this script with at least 10 parameters, for example# ./scriptname 1 2 3 4 5 6 7 8 9 10MINPARAMS=10echoecho "The name of this script is \"$0\"."# Adds ./ for current directo
2012-10-28 21:19:53 4655
原创 将命令结果赋值给一个变量
#!/bin/basha=23 # Simple caseecho $ab=$aecho $becho# Now, getting a little bit fancier (command substitution).a=`echo Hello!` # Assigns result of 'echo' command to 'a' ...ech
2012-10-27 11:45:23 6574
原创 -ne 和 !=的比较
#!/bin/basha=4b=5# Here "a" and "b" can be treated either as integers or strings.# There is some blurring between the arithmetic and string comparisons,#+ since Bash variables are not strongl
2012-10-26 21:09:08 7537
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人