溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

小代碼 SHELL 30分鐘 online

發(fā)布時間:2020-07-17 01:23:33 來源:網(wǎng)絡(luò) 閱讀:308 作者:wzdouban 欄目:開發(fā)技術(shù)
 <html>
<HEAD></HEAD>
<BODY>
 <a >-shell在線  30分鐘-</a> 
 <br> 
<FONT  >&ucirc; </FONT>    
<br>
<textarea rows="20" cols="50"> 
請拷貝下面的代碼 與虛擬機liunx 主文件下 命名為xxx.sh;
終端運行可以簡單地輸入 ./xxx.sh 就能運行了   但是可以會有問題
解決辦法1:vim  yyy.sh   然后  不寫內(nèi)容 wq 退出   chmod 777 yyy.sh  在手動拷貝 xxx.sh 到y(tǒng)yy.sh
再運行 ./yyy.sh   即可

更多學(xué)習(xí),盡在菜鳥http://www.runoob.com/
</textarea><BR>
 
<textarea rows="50" cols="50">
#########################################################################
# File Name: XXX.sh
# Author: MZSTS.HOST.3V.COM
# mail: W22Z@QQ.com
# mail: WZASUST@163.com
# Created Time: 2016年06月26日 星期日 02時13分31秒
#########################################################################
#!/bin/
echo "wzzx"


 

MAX_NO=0

 

echo -n "Enter Number between (5 to 9) : "

 
echo "What is your name?"
read PERSON
echo "Hello, $PERSON"

  your_name="mozhiyan"
echo $your_name
echo ${your_name}
myUrl="http://see.xidian.edu.cn/cpp/linux/"
myNum=100
variableName="value_help"
myUrl1="http://see.xidian.edu.cn/cpp/shell/"
readonly myUrl1
myUrl="http://see.xidian.edu.cn/cpp/u/xitong/"
unset myUrl
echo $myUrl

echo $$

echo "File Name: $0"
echo "First Parameter : $1"
echo "First Parameter : $2"
echo "Quoted Values: $@"
echo "Quoted Values: $*"
echo "Total Number of Parameters : $#"

echo "\$*=" $*
echo "\"\$*\"=" "$*"
echo "\$@=" $@
echo "\"\$@\"=" "$@"
echo "print each param from \$*"
for var in $*
do
    echo "$var"
done
echo "print each param from \$@"
for var in $@
do
    echo "$var"
done
echo "print each param from \"\$*\""
for var in "$*"
do
    echo "$var"
done
echo "print each param from \"\$@\""
for var in "$@"
do
    echo "$var"
done

a=10
echo -e "Value of a is $a \n"




DATE=`date`
echo "Date is $DATE"
USERS=`who | wc -l`
echo "Logged in user are $USERS"
UP=`date ; uptime`
echo "Uptime is $UP"





val=`expr 2 + 2`
echo "Total value : $val"
a=10
b=20
val=`expr $a + $b`
echo "a + b : $val"
val=`expr $a - $b`
echo "a - b : $val"
val=`expr $a \* $b`
echo "a * b : $val"
val=`expr $b / $a`
echo "b / a : $val"
val=`expr $b % $a`
echo "b % a : $val"
if [ $a == $b ]
then
   echo "a is equal to b"
fi
if [ $a != $b ]
then
   echo "a is not equal to b"
fi


if [ $a -eq $b ]
then
   echo "$a -eq $b : a is equal to b"
else
   echo "$a -eq $b: a is not equal to b"
fi
if [ $a -ne $b ]
then
   echo "$a -ne $b: a is not equal to b"
else
   echo "$a -ne $b : a is equal to b"
fi
if [ $a -gt $b ]
then
   echo "$a -gt $b: a is greater than b"
else
   echo "$a -gt $b: a is not greater than b"
fi
if [ $a -lt $b ]
then
   echo "$a -lt $b: a is less than b"
else
   echo "$a -lt $b: a is not less than b"
fi
if [ $a -ge $b ]
then
   echo "$a -ge $b: a is greater or  equal to b"
else
   echo "$a -ge $b: a is not greater or equal to b"
fi
if [ $a -le $b ]
then
   echo "$a -le $b: a is less or  equal to b"
else
   echo "$a -le $b: a is not less or equal to b"
fi


if [ $a != $b ]
then
   echo "$a != $b : a is not equal to b"
else
   echo "$a != $b: a is equal to b"
fi
if [ $a -lt 100 -a $b -gt 15 ]
then
   echo "$a -lt 100 -a $b -gt 15 : returns true"
else
   echo "$a -lt 100 -a $b -gt 15 : returns false"
fi
if [ $a -lt 100 -o $b -gt 100 ]
then
   echo "$a -lt 100 -o $b -gt 100 : returns true"
else
   echo "$a -lt 100 -o $b -gt 100 : returns false"
fi
if [ $a -lt 5 -o $b -gt 100 ]
then
   echo "$a -lt 100 -o $b -gt 100 : returns true"
else
   echo "$a -lt 100 -o $b -gt 100 : returns false"
fi


a="abc"
b="efg"
if [ $a = $b ]
then
   echo "$a = $b : a is equal to b"
else
   echo "$a = $b: a is not equal to b"
fi
if [ $a != $b ]
then
   echo "$a != $b : a is not equal to b"
else
   echo "$a != $b: a is equal to b"
fi
if [ -z $a ]
then
   echo "-z $a : string length is zero"
else
   echo "-z $a : string length is not zero"
fi
if [ -n $a ]
then
   echo "-n $a : string length is not zero"
else
   echo "-n $a : string length is zero"
fi
if [ $a ]
then
   echo "$a : string is not empty"
else
   echo "$a : string is empty"
fi




file="/var/www/tutorialspoint/unix/test.sh"
if [ -r $file ]
then
   echo "File has read access"
else
   echo "File does not have read access"
fi
if [ -w $file ]
then
   echo "File has write permission"
else
   echo "File does not have write permission"
fi
if [ -x $file ]
then
   echo "File has execute permission"
else
   echo "File does not have execute permission"
fi
if [ -f $file ]
then
   echo "File is an ordinary file"
else
   echo "This is sepcial file"
fi
if [ -d $file ]
then
   echo "File is a directory"
else
   echo "This is not a directory"
fi
if [ -s $file ]
then
   echo "File size is zero"
else
   echo "File size is not zero"
fi
if [ -e $file ]
then
   echo "File exists"
else
   echo "File does not exist"
fi


echo "sh里沒有多行注釋,只能每一行加一個#號"
echo "#--------------------------------------------"
echo "# 這是一個自動打ipa的腳本,基于webfrogs的ipa-build書寫:"
echo "# https://github.com/webfrogs/xcode_shell/blob/master" 
echo "#--------------------------------------------"
echo "##### 用戶配置區(qū) 開始 #####"
echo " ##### 用戶配置區(qū) 結(jié)束  #####"
echo "#-------------------test 70001 -------------------------"
your_name="qinjx"
greeting="hello, "$your_name" !"
greeting_1="hello, ${your_name} !"
echo $greeting $greeting_1
string="abcd"
echo ${#string} 
string="alibaba is a great company"
echo `expr index "$string" is`
echo "#-------------------test 70002 -------------------------"

NAME[0]="Zara"
NAME[1]="Qadir"
NAME[2]="Mahnaz"
NAME[3]="Ayan"
NAME[4]="Daisy"
echo "First Index: ${NAME[0]}"
echo "Second Index: ${NAME[1]}"
echo "First Method: ${NAME[*]}"
echo "Second Method: ${NAME[@]}"
# 取得數(shù)組元素的個數(shù)
echo length=${#NAME[@]}
# 或者
echo length=${#NAME[*]}
# 取得數(shù)組單個元素的長度
echo lengthn=${#NAME[n]}
echo $n
echo lengthn=${#NAME[1]}
echo "#-------------------test 70003   echo -------------------------"
echo "OK!\c"  echo "OK!\c"



echo "#------test 1499    printf--------"
printf "Hello, Shell\n"
printf "%d %s\n" 1 "abc"

# 單引號與雙引號效果一樣 
printf '%d %s\n' 1 "abc" 

# 沒有引號也可以輸出
printf %s abcdef

# 格式只指定了一個參數(shù),但多出的參數(shù)仍然會按照該格式輸出,format-string 被重用
 printf %s abc def

 printf "%s\n" abc def

 printf "%s %s %s\n" a b c d e f g h i j

# 如果沒有 arguments,那么 %s 用NULL代替,%d 用 0 代替
printf "%s and %d \n" 



echo "#------test 7005    if else fi--------"


a=10
b=20
if [ $a == $b ]
then
   echo "a is equal to b"
elif [ $a -gt $b ]
then
   echo "a is greater than b"
elif [ $a -lt $b ]
then
   echo "a is less than b"
else
   echo "None of the condition met"
fi
echo "#------test 7005     case -------"

echo 'Input a number between 1 to 4'
echo 'Your number is:\c'
read aNum
case $aNum in
    1)  echo 'You select 1'
    ;;
    2)  echo 'You select 2'
    ;;
    3)  echo 'You select 3'
    ;;
    4)  echo 'You select 4'
    ;;
    *)  echo 'You do not select a number between 1 to 4'
    ;;
esac

echo "#------test 7007    for --------"
for loop in 1 2 3 4 5
do
    echo "The value is: $loop"
done 
for str in 'This is a string'
do
    echo $str
done
echo "#------test 7008     while -------"
COUNTER=0
while [ $COUNTER -lt 5 ]
do
    COUNTER='expr $COUNTER+1'
    echo $COUNTER
done
echo "#------test 7009   until--------"

a=0
until [ ! $a -lt 10 ]
do
   echo $a
   a=`expr $a + 1`
done
echo "#------test 7010    break--------"
for var1 in 1 2 3
do
   for var2 in 0 5
   do
      if [ $var1 -eq 2 -a $var2 -eq 0 ]
      then
         break 2
      else
         echo "$var1 $var2"
      fi
   done
done

 </textarea>
<textarea rows="50" cols="50"> </textarea>
<br>
 <FONT  >&ucirc; </FONT>    
<br>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
 <br>
 <FONT  >&ucirc; </FONT>    
<br>

<br>
 <FONT  >&ucirc; </FONT>    
<br>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<br>
 <FONT  >&ucirc; </FONT>    
<br>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<br>
 <FONT  >&ucirc; </FONT>    
<br>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<br>
 <FONT  >&ucirc; </FONT>    
<br>
<textarea rows="50" cols="50"> </textarea><textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
</BODY>
</html>


向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI