亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
12下一頁(yè)
最近訪問(wèn)板塊 發(fā)新帖
查看: 7755 | 回復(fù): 13
打印 上一主題 下一主題

shell中變量自加導(dǎo)致崩潰,請(qǐng)教大家 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-03-02 23:37 |只看該作者 |倒序?yàn)g覽
本帖最后由 蟲蟲2003 于 2011-03-08 08:56 編輯

我這邊有個(gè)shell腳本,里面會(huì)反復(fù)調(diào)用函數(shù),像這樣:
  1. set +e

  2. ECHO "unpacking source/lib/ncurses-5.5"
  3. mkdir -pv source/lib
  4. run_command_progress_float "tar -xvzf pub/tarball/ncurses-5.5.tgz -C source/lib/" 0         "tar -tzf pub/tarball/ncurses-5.5.tgz | wc -l"

  5. ECHO "unpacking source/lib/expat-1.95.8"
  6. mkdir -pv source/lib
  7. run_command_progress_float "tar -xvzf pub/tarball/expat-1.95.8.tgz -C source/lib/" 0         "tar -tzf pub/tarball/expat-1.95.8.tgz | wc -l"

  8. .......
復(fù)制代碼
函數(shù)run_command_progress_float是這樣的:
  1. # $1: command
  2. # $2: total
  3. # $3: command to calc totals
  4. run_command_progress_float()
  5. {
  6.         local readonly RCP_RANGE=50
  7.         local rcp_lines=0
  8.         local rcp_nextpos=1
  9.         local rcp_total=0
  10.         local progress_bar=
  11.         local rcp_prog=0
  12.         local rcp_tmp=0
  13.         local prog_bar_base=
  14.         local rcp_percent=0

  15.         ECHO "run_command_progress_float: '$1'"

  16.         if [ -n "$3" ] ;
  17.         then
  18.                 echo -n "Initializing progress bar ..."
  19.                 rcp_total=`eval $3`;
  20.                 echo -n "\r"
  21.                 [ -z "$rcp_total" ] && rcp_total=1
  22.         else
  23.                 [ -n "$2" ] && rcp_total=$2
  24.         fi

  25.         [ -z "$rcp_total" ] && rcp_total=1
  26.         [ $rcp_total -le 0 ] && rcp_total=1

  27.         prog_bar_base="[    ]"

  28.         while [ $rcp_tmp -lt $RCP_RANGE ]
  29.         do
  30.                 prog_bar_base="$prog_bar_base-"

  31.                 ((rcp_tmp++))
  32. #                ((rcp_tmp+=1))
  33. #                rcp_tmp=$[rcp_tmp+1]

  34. #                echo "rcp_tmp=$rcp_tmp"
  35.         done
  36.         prog_bar_base="${prog_bar_base}|"
  37.         printf "\r$prog_bar_base\r"

  38.         set +e
  39.         eval $1 | while read line
  40.         do
  41.                 ((rcp_lines++))

  42.                 if [ $rcp_lines -ge $rcp_nextpos ]
  43.                 then
  44.                         rcp_percent=`expr \( $rcp_lines \* 101 - 1 \) / $rcp_total `
  45.                         rcp_prog=`expr \( $rcp_lines \* \( $RCP_RANGE + 1 \) - 1 \) / $rcp_total `
  46.                         [ $rcp_prog -gt $RCP_RANGE ] && rcp_prog=$RCP_RANGE
  47.                         rcp_nextpos=`expr \( \( $rcp_percent + 1 \) \* $rcp_total \) / 100`
  48.                         [ $rcp_nextpos -gt $rcp_total ] && rcp_nextpos=$rcp_total

  49.                         rcp_tmp=0
  50.                         progress_bar=""
  51.                         while [ $rcp_tmp -lt $rcp_prog ]
  52.                         do
  53.                                 progress_bar="$progress_bar#"
  54.                                 ((rcp_tmp++))
  55.                         done
  56.                         printf "\r$prog_bar_base\r[%3d%%]$progress_bar\r" $rcp_percent
  57.                 fi
  58.         done
  59.         set -e

  60.         echo ""
  61. }
復(fù)制代碼
現(xiàn)在問(wèn)題就出在while [ $rcp_tmp -lt $RCP_RANGE ]中的((rcp_tmp++))這句上,run_command_progress_float只能成功執(zhí)行一次,第二次執(zhí)行時(shí)跑到((rcp_tmp++))就會(huì)崩潰,退出腳本,而我把這句改為((rcp_tmp+=1))或者rcp_tmp=$[rcp_tmp+1]就沒(méi)有問(wèn)題。
我是在ubuntu下運(yùn)行的,好象是從10以后的版本出現(xiàn)這個(gè)問(wèn)題的,以前用9.10是不會(huì)出錯(cuò)的。
不知到是怎么回事,請(qǐng)大家?guī)兔纯,?yīng)該怎么寫。
謝謝!

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2011-03-02 23:40 |只看該作者
另外還想問(wèn)下,的set +e、set -e、printf引號(hào)中的\r分別是意思?

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2011-03-03 09:30 |只看該作者
請(qǐng)大家?guī)兔纯?/td>

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2011-03-03 09:31 |只看該作者
請(qǐng)大家?guī)兔纯。!?/td>

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2011-03-03 09:40 |只看該作者
請(qǐng)大家?guī)兔纯。!?/td>

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
6 [報(bào)告]
發(fā)表于 2011-03-03 09:41 |只看該作者
我這邊有個(gè)shell腳本,里面會(huì)反復(fù)調(diào)用函數(shù),像這樣:函數(shù)run_command_progress_float是這樣的:現(xiàn)在問(wèn)題就出 ...
蟲蟲2003 發(fā)表于 2011-03-02 23:37
bash當(dāng)中似乎沒(méi)有這種自加的語(yǔ)法。

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
7 [報(bào)告]
發(fā)表于 2011-03-03 09:45 |只看該作者
另外還想問(wèn)下,的set +e、set -e、printf引號(hào)中的\r分別是意思?
蟲蟲2003 發(fā)表于 2011-03-02 23:40
這個(gè)你看bash的幫助頁(yè)就知道了。
       set [+abefhkmnptuvxBCEHPT] [+o option] [arg ...]
              Without options, the name and value of each shell  variable  are
              displayed in a format that can be reused as input for setting or
              resetting the currently-set variables.  Read-only variables can‐
              not  be  reset.  In posix mode, only shell variables are listed.
              The output is sorted according  to  the  current  locale.   When
              options  are specified, they set or unset shell attributes.  Any
              arguments remaining after option processing are treated as  val‐
              ues for the positional parameters and are assigned, in order, to
              $1, $2, ...  $n.  Options,  if  specified,  have  the  following
              meanings:
              -a      Automatically  mark  variables  and  functions which are
                      modified or created for export  to  the  environment  of
                      subsequent commands.
              -b      Report  the status of terminated background jobs immedi‐
                      ately, rather than before the next primary prompt.  This
                      is effective only when job control is enabled.
              -e      Exit  immediately  if a pipeline (which may consist of a
                      single simple command),  a subshell command enclosed  in
                      parentheses,  or one of the commands executed as part of
                      a command list enclosed by  braces  (see  SHELL  GRAMMAR
                      above) exits with a non-zero status.  The shell does not
                      exit if the command that fails is part  of  the  command

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2011-03-03 09:50 |只看該作者
bash當(dāng)中似乎沒(méi)有這種自加的語(yǔ)法。
L_kernel 發(fā)表于 2011-03-03 09:41


那正確的應(yīng)該怎么寫?

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2011-03-03 13:47 |只看該作者
本帖最后由 南極雨 于 2011-03-03 13:50 編輯
這個(gè)你看bash的幫助頁(yè)就知道了。
L_kernel 發(fā)表于 2011-03-03 09:45


我的shell為什么沒(méi)有 sed + 這類的幫助啊 ?
還有,這段的意思是不是這個(gè):每個(gè)shell變量的名稱和值會(huì)格式化并打印出來(lái),并且能作為輸入(設(shè)置或者重置當(dāng)前的變量)重新利用,只讀的變量不能設(shè)置。在posix系統(tǒng)環(huán)境中,只輸出shell變量,并根據(jù)當(dāng)前的語(yǔ)言環(huán)境排序。一些特殊選項(xiàng)來(lái)設(shè)置或者重置shell環(huán)境變量。

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
10 [報(bào)告]
發(fā)表于 2011-03-04 20:11 |只看該作者
那正確的應(yīng)該怎么寫?
蟲蟲2003 發(fā)表于 2011-03-03 09:50
改為通常意義上的rcp_tmp+1就可以了。
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP