• <em id="6vhwh"><rt id="6vhwh"></rt></em>

    <style id="6vhwh"></style>

    <style id="6vhwh"></style>
    1. <style id="6vhwh"></style>
        <sub id="6vhwh"><p id="6vhwh"></p></sub>
        <p id="6vhwh"></p>
          1. 国产亚洲欧洲av综合一区二区三区 ,色爱综合另类图片av,亚洲av免费成人在线,久久热在线视频精品视频,成在人线av无码免费,国产精品一区二区久久毛片,亚洲精品成人片在线观看精品字幕 ,久久亚洲精品成人av秋霞

            SHELL四則運算(shell四則運算的四種方式)

            更新時間:2023-03-02 05:05:43 閱讀: 評論:0

            1.linux系統下shell腳本用ca語句編寫四則運算 2.linux系統下shell腳本輸入數字串。進行反序輸出

            原來我拿shell寫的計算器:
            [root@liuxiting testdir]# cat calculator.sh
            #!/bin/bash
            echo "usage: 1+3 <Enter> ,q <Enter> is quit"
            while [ 1 ]
            do
            read -p "->>" str 1>>/dev/null
            a=`echo $str |awk -F '+|-|*|/' '{print $1}'`
            if [ $a == q ]
            then
            break
            fi
            b=`echo $str |awk -F '+|-|*|/' '{print $2}'`
            o=`echo $str |grep -o "[[:punct:]]" | grep -v "\."`
            ca $o in
            +) awk 'BEGIN{printf " =%.2f\n",'$a'+'$b'}';;
            -) awk 'BEGIN{printf " =%.2f\n",'$a'-'$b'}';;
            \*) awk 'BEGIN{printf " =%.2f\n",'$a'*'$b'}';;
            /)if [ $b -eq 0 ]
            then
            echo 0 Can NOT be denominator!
            continue
            fi
            awk 'BEGIN{printf " =%.2f\n",'$a'/'$b'}';;
            #^) awk 'BEGIN{printf " =%.2f\n",'$a'**'$b'}';;
            *) echo error;;
            esac
            done

            剛剛寫的倒序輸出:
            [root@liuxiting testdir]# cat daoXuShuChu.sh
            #!/bin/bash
            echo "usage: 123456 <Enter>, q <Enter> is quit"
            while [ 1 ]
            do
            echo -n "Pleasw enter number : "
            read n
            if [ $n == 'q' ]
            then
            break
            fi
            sd=0
            rev=""
            on=$n
            echo "$n"
            while [ $n -gt 0 ]
            do
            sd=$(( $n % 10 )) # get Remainder
            n=$(( $n / 10 )) # get next digit
            rev=$( echo $rev$sd)
            done
            echo "$on in a rever order $rev"
            done

            用shell做個加減乘除運算

            看到真有點疑惑,不是做加法怎么去做減法了。其次t是設置shell變量吧。
            還有前兩個參數不是數字,最后一個是運算符么?怎么還去測試第三個參數和第一個參數相等。

            以下是根據你例子修改的(沒檢查位置參數不全,不正確這類異常情況。)

            #!/bin/bash

            exportd=0
            if["$3"-eq"+"]
            then
            echo$3
            d=$(($1+$2))
            fi
            echo$d

            shell 腳本里面從一個文本里面讀出一個數字,如何轉換成整數?我需要用這個數字進行加減乘除

            可以參考下面幾種方法:

            法一:

            echo ${var%.*} #這個是直接去除小數點及后面所有內容,只用于bash

            法二:

            echo $var | awk -F. '{print $1}' #以小數點為分隔符取第一個字段

            法三:

            echo $var | awk '{print int($0)}' #awk中可直接使用C函數取整

            擴展資料:

            shell腳本

            shell script是利用shell的功能所寫的一個程序,這個程序是使用純文本文件,將一些shell的語法與指令寫在里面,然后用正規表示法,管道命令以及數據流重導向等功能,以達到我們所想要的處理目的。

            更明白地來說,shell script就像早期dos年代的.bat,最簡單的功能就是將許多指令匯整寫一起,讓使用者很容易地就能夠一個操作執行多個命令。

            參考資料來源:百度百科-Shell腳本


            在Linux下,用shell編寫一個簡單的計算器,要實現加減乘除4個功能就行了

            不用寫吧,本來有個 bc 命令可用,沒有下載就成.
            非要寫一個,zsh 的function里有一個,名 zcalc,
            貼上來給你

            #!/usr/bin/zsh -i
            #
            # Zsh calculator. Understands most ordinary arithmetic expressions.
            # Line editing and history are available. A blank line or `q' quits.
            #
            # Runs as a script or a function. If ud as a function, the history
            # is remembered for reu in a later call (and also currently in the
            # shell's own history). There are various problems using this as a
            # script, so a function is recommended.
            #
            # The prompt shows a number for the current line. The corresponding
            # result can be referred to with $<line-no>, e.g.
            # 1> 32 + 10
            # 42
            # 2> $1 ** 2
            # 1764
            # The t of remembered numbers is primed with anything given on the
            # command line. For example,
            # zcalc '2 * 16'
            # 1> 32 # printed by function
            # 2> $1 + 2 # typed by ur
            # 34
            # 3>
            # Here, 32 is stored as $1. This works in the obvious way for any
            # number of arguments.
            #
            # If the mathfunc library is available, probably understands most system
            # mathematical functions. The left parenthesis must be adjacent to the
            # end of the function name, to distinguish from shell parameters
            # (translation: to prevent the maintainers from having to write proper
            # lookahead parsing). For example,
            # 1> sqrt(2)
            # 1.4142135623730951
            # is right, but `sqrt (2)' will give you an error.
            #
            # You can do things with parameters like
            # 1> pi = 4.0 * atan(1)
            # too. The go into global parameters, so be careful. You can declare
            # local variables, however:
            # 1> local pi
            # but note this can't appear on the same line as a calculation. Don't
            # u the variables listed in the `local' and `integer' lines below
            # (translation: I can't be bothered to provide a sandbox).
            #
            # Some constants are already available: (ca nsitive as always):
            # PI pi, i.e. 3.1415926545897931
            # E e, i.e. 2.7182818284590455
            #
            # You can also change the output ba.
            # 1> [#16]
            # 1>
            # Changes the default output to hexadecimal with numbers preceded by `16#'.
            # Note the line isn't remembered.
            # 2> [##16]
            # 2>
            # Change the default output ba to hexadecimal with no prefix.
            # 3> [#]
            # Ret the default output ba.
            #
            # This is bad on the builtin feature that you can change the output ba
            # of a given expression. For example,
            # 1> [##16] 32 + 20 / 2
            # 2A
            # 2>
            # prints the result of the calculation in hexadecimal.
            #
            # You can't change the default input ba, but the shell allows any small
            # integer as a ba:
            # 1> 2#1111
            # 15
            # 2> [##13] 13#6 * 13#9
            # 42
            # and the standard C-like notation with a leading 0x for hexadecimal is
            # also understood. However, leading 0 for octal is not understood --- it's
            # too confusing in a calculator. U 8#777 etc.
            #
            # Options: -#<ba> is the same as a line containing just `[#<ba>],
            # similarly -##<ba>; they t the default output ba, with and without
            # a ba discriminator in front, respectively.
            #
            #
            # To do:
            # - parate zcalc history from shell history using arrays --- or allow
            # zsh to switch internally to and from array-bad history.

            emulate -L zsh
            topt extendedglob

            local line ans ba defba forms match mbegin mend psvar optlist opt arg
            local compcontext="-math-"
            integer num outdigits outform=1
            # We u our own history file with an automatic pop on exit.
            history -ap "${ZDOTDIR:-$HOME}/.zcalc_history"

            forms=( '%2$g' '%.*g' '%.*f' '%.*E' )

            zmodload -i zsh/mathfunc 2>/dev/null

            : ${ZCALCPROMPT="%1v> "}

            # Supply some constants.
            float PI E
            (( PI = 4 * atan(1), E = exp(1) ))

            # Process command line
            while [[ -n $1 && $1 = -(|[#-]*) ]]; do
            optlist=${1[2,-1]}
            shift
            [[ $optlist = (|-) ]] && break
            while [[ -n $optlist ]]; do
            opt=${optlist[1]}
            optlist=${optlist[2,-1]}
            ca $opt in
            ('#') # Default ba
            if [[ -n $optlist ]]; then
            arg=$optlist
            optlist=
            elif [[ -n $1 ]]; then
            arg=$1
            shift
            el
            print "-# requires an argument" >&2
            return 1
            fi
            if [[ $arg != (|\#)[[:digit:]]## ]]; then
            print - "-# requires a decimal number as an argument" >&2
            return 1
            fi
            defba="[#${arg}]"
            ;;
            esac
            done
            done

            for (( num = 1; num <= $#; num++ )); do
            # Make sure all arguments have been evaluated.
            # The `$' before the cond argv forces string rather than numeric
            # substitution.
            (( argv[$num] = $argv[$num] ))
            print "$num> $argv[$num]"
            done

            psvar[1]=$num
            while vared -cehp "${(%)ZCALCPROMPT}" line; do
            [[ -z $line ]] && break
            # special cas
            # Set default ba if `[#16]' or `[##16]' etc. on its own.
            # Unt it if `[#]' or `[##]'.
            if [[ $line = (#b)[[:blank:]]#('[#'(\#|)(<->|)']')[[:blank:]]#(*) ]]; then
            if [[ -z $match[4] ]]; then
            if [[ -z $match[3] ]]; then
            defba=
            el
            defba=$match[1]
            fi
            print -s -- $line
            line=
            continue
            el
            ba=$match[1]
            fi
            el
            ba=$defba
            fi

            print -s -- $line

            ca ${${line##[[:blank:]]#}%%[[:blank:]]#} in
            q) # Exit if `q' on its own.
            return 0
            ;;
            norm) # restore output format to default
            outform=1
            ;;
            sci[[:blank:]]#(#b)(<->)(#B))
            outdigits=$match[1]
            outform=2
            ;;
            fix[[:blank:]]#(#b)(<->)(#B))
            outdigits=$match[1]
            outform=3
            ;;
            eng[[:blank:]]#(#b)(<->)(#B))
            outdigits=$match[1]
            outform=4
            ;;
            local([[:blank:]]##*|))
            eval $line
            line=
            continue
            ;;
            *)
            # Latest value is stored as a string, becau it might be floating
            # point or integer --- we don't know till after the evaluation, and
            # arrays always store scalars anyway.
            #
            # Since it's a string, we'd better make sure we know which
            # ba it's in, so don't change that until we actually print it.
            eval "ans=\$(( $line ))"
            # on error $ans is not t; let ur re-edit line
            [[ -n $ans ]] || continue
            argv[num++]=$ans
            psvar[1]=$num
            ;;
            esac
            if [[ -n $ba ]]; then
            print -- $(( $ba $ans ))
            elif [[ $ans = *.* ]] || (( outdigits )); then
            printf "$forms[outform]\n" $outdigits $ans
            el
            printf "%d\n" $ans
            fi
            line=
            done

            return 0

            支援小數點,+ - * / , ok

            本文發布于:2023-02-28 20:52:00,感謝您對本站的認可!

            本文鏈接:http://www.newhan.cn/zhishi/a/167770474396449.html

            版權聲明:本站內容均來自互聯網,僅供演示用,請勿用于商業和其他非法用途。如果侵犯了您的權益請與我們聯系,我們將在24小時內刪除。

            本文word下載地址:SHELL四則運算(shell四則運算的四種方式).doc

            本文 PDF 下載地址:SHELL四則運算(shell四則運算的四種方式).pdf

            標簽:四種   方式   SHELL   shell
            相關文章
            留言與評論(共有 0 條評論)
               
            驗證碼:
            推薦文章
            排行榜
            Copyright ?2019-2022 Comsenz Inc.Powered by ? 實用文體寫作網旗下知識大全大全欄目是一個全百科類寶庫! 優秀范文|法律文書|專利查詢|
            主站蜘蛛池模板: 2021亚洲va在线va天堂va国产 | 国产在线精品欧美日韩电影| 九九热免费公开视频在线| 99久久免费精品色老| 人人玩人人添人人澡超碰| 国产精品爽黄69天堂A| 午夜免费无码福利视频麻豆| 人妻少妇无码精品专区| 国产超碰人人爱被ios解锁| 18禁视频一区二区三区| 无码少妇一区二区三区浪潮av| 国产av一区二区麻豆熟女| 国产精品毛片av999999| 国产精品久久无码不卡黑寡妇| 国产欧美日韩视频怡春院| 国产又粗又爽视频| 一本一本久久A久久精品综合不卡| 国产农村妇女一区二区三区| 国产精品无码av不卡| 东方四虎在线观看av| 人妻丝袜AV中文系列先锋影音| 国产裸体美女永久免费无遮挡 | 国产成人久久综合一区| 一边摸一边做爽的视频17国产| 中文字幕亚洲精品人妻| 人人人妻人人澡人人爽欧洲一区| 人妻少妇偷人无码视频| 老熟女重囗味hdxx69| 九九久久人妻精品一区色| 久久无码中文字幕免费影院蜜桃 | 92精品国产自产在线观看481页| 亚洲天堂欧洲| 高清中文字幕国产精品| 91麻豆国产视频| 亚洲熟妇熟女久久精品一区| 国产成人av片在线观看| 国产精品乱一区二区三区| 熟妇的奶头又大又长奶水视频| 国产亚洲精品久久综合阿香| 欧美在线精品一区二区三区| 年轻女教师hd中字3|