linux shell 脚本实例代码分享,讲解关于linux shell使用脚本的方法。
#!/bin/bashname=Tomif grep "$name" databasefile > /dev/null 2>&1then :else echo " not found in databasefile" exit 1fi#!/bin/bash# Scriptname: nosyecho -e "Are you happy? /c"read answerecho "$answer is the right response."echo -e "What is your full name? /c"read first mIDdle lastecho "Hello $first"echo -n "Where do you work? "readecho I guess $REPLY keeps you busy!#------------------------------------------------read -p "Enter your job Title: "echo "I thought you might be an $REPLY."echo -n "Who are your best frIEnds? "read -a frIEndsecho "Say hi to ${frIEnds[2]}."#!/bin/sh# file: perm_check# Using the old style test commandfile=./testingfile=./c8if [ -d $file ]then echo "$file is a directory"elif [ -f $file ]then if [ -r $file -a -w $file -a -x $file ] then # nested if command echo "You have read,write,and execute / permission on $file." fielse echo "$file is neither a file nor a directory. "fi#!/bin/sh# file: perm_check2# Using the old style test commandfile=./testingif [[ -d $file ]]then echo "$file is a directory"elif [[ -f $file ]]then if [[ -rwx $file ]] then # nested if command echo "You have read,and execute / permission on $file." fielse echo "$file is neither a file nor a directory. "fi#!/bin/bash# Scriptname: printer_check# Script to clear a hung up printerif [ $LOGname != root ]then echo "Must have root privileges to run this program" exit 1ficat << EOFWarning: All jobs in the printer queue will be removed.Please turn off the printer Now. Press return when youare ready to continue. Otherwise press Control C.EOFread JUNK # Wait until the user turns off the printerecho/etc/rc.d/init.d/lpd stop # Stop the printerecho -e "/nPlease turn the printer on Now."echo "Press return to continue"read JUNK # Stall until the user turns the printer # back onecho # A blank line is printed/etc/rc.d/init.d/lpd start # Start the printer#!/bin/bash# Scriptname: tellme# Using the old-style test commandecho -n "How old are you? "read ageif [ $age -lt 0 -o $age -gt 120 ]then echo "Welcome to our planet! " exit 1fiif [ $age -ge 0 -a $age -le 12 ]then echo "A child is a garden of verses"elif [ $age -ge 12 -a $age -le 19 ]then echo "Rebel without a cause"elif [ $age -ge 20 -a $age -le 29 ]then echo "You got the world by the tail!!"elif [ $age -ge 30 -a $age -le 39 ]then echo "Thirty something..."else echo "Sorry I asked"fi#!/bin/bash# Scriptname: tellme# Using the new (( )) compound let commandecho -n "How old are you? "read ageif (( age < 0 || age > 120 ))then echo "Welcome to our planet! " exit 1fiif ((age >= 0 && age <= 12))then echo "A child is a garden of verses"elif ((age >= 13 && age <= 19 ))then echo "Rebel without a cause"elif (( age >= 19 && age <= 29 ))then echo "You got the world by the tail!!"elif (( age >= 30 && age <= 39 ))then echo "Thirty something..."else echo "Sorry I asked"fi#!/bin/bash# name:wholenum# Purpose:The linux expr command tests that the user enters an# integer#echo "Enter a number."read numberif expr "$number" + 0 > /dev/null 2>&1then :else echo "You dID not enter an integer value." exit 1fi#!/bin/bash# Scriptname: xcolorsecho -n "Choose a foreground color for your xterm window: "read colorcase "$color" in [Bb]l??) xterm -fg blue -fn terminal & ;; [Gg]ree*) xterm -fg darkgreen -fn terminal & ;; red | orange) # The vertical bar means "or" xterm -fg "$color" -fn terminal & ;; *) xterm -fn terminal ;;esacecho "Out of case"#!/bin/bash# Scriptname: backup# Purpose:# Create backup files and store them in a backup directory#dir=/home/jody/ellIE/backupscriptsfor file in memo[1-5]do if [ -f $file ] then cp $file $dir/$file.bak echo "$file is backed up in $dir" fidone#!/bin/bash# Scriptname: dater# Purpose: set positional parameters with the set command# and shift through the parameters.set $(date)while (( $# > 0 )) # or [ $# -gt 0 ]do echo shiftdone总结
以上是内存溢出为你收集整理的Linux shell 脚本实例全部内容,希望文章能够帮你解决Linux shell 脚本实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)