Bash Shell Basics

Source: Internet
Author: User

Bash a few common code

######## #最简单的bash

#! /bin/bash    #解析器路径 env                     #查看环境

######### #看运行时间

#!/bin/time. SH start=$ (date +%s) #commands; #statements; Sleep Ten ;               #command End=$ (date +%s) Difference=$ ((End- start))echo time taken To execute $0 is $difference seconds.

########## while loop

#!/bin/-i i= 1sum=0while ((i<=))         do sum + = i + I done echo $ sum       

########## about the interrupt cursor

#!/bin/bash# file name:Sleep.SHEcho-n count:# tput SC storage cursor position tput Sccount=0; while true; Do    if[$count-lt + ];  ThenLet count++; Sleep 1; # The command to restore the cursor position is tput RC tput RC # tput Ed clears all content from the current cursor position to the end of the line tput EdEcho-n $count; ElseExit0; fi Done

########### #shell判断

#! /bin/Bashdeclare-I. num=0if[$num-lt0] There is a space between the #一定要注意在 [or] and the operand Then    Echo "<";elif[$num-eq0 ] Then    Echo "==";Else    Echo ">";fi# [$var 1-ne0-A $var 2-GT2] #使用逻辑与-a# [$var 1-ne0-O VAR2-GT2] #逻辑或-O

########### #shell Debug

#!/bin/bash# file name: Debug. SH  for inch {1.. 6 };  Do -x    echo  $i    +xdone echo      " Script executed "

########### #break

#!/bin/Bash while : Do    Echo-N"Input A number between 1 to 5:"Read Anum Case$aNuminch        1|2|3|4|5)Echo "Your number is $aNum!"                    ;; *)Echo "You does not select a number between 1 to 5, the game is over!"Break ;; Esac Done

############# #case

#! /bin/BashEcho 'Input A number between 1 to 4'Echo 'Your number is:\c'Read Anum Case$aNuminch     1)Echo 'You select 1'             ;; 2)Echo 'You select 2'             ;; 3)Echo 'You select 3'             ;; 4)Echo 'You Select 4'             ;; *)Echo 'You does not select a number between 1 to 4'             ;;Esac

######## #function

function fname () {    echo $1, $2; #访问参数1和参数2    echo" [email protected] " ; #以列表的方式一次性打印所有参数     Echo " $* " ; #类似于 [email protected], but the parameter is used as    a single entity 0  -F fname

Bash Shell Basics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.