用script 讀檔然後做變數 - Linux

Frederic avatar
By Frederic
at 2012-04-06T11:20

Table of Contents

PATH=$PATH
export PATH

cat ttest.dat | awk '{total = $1 + $2 + $3 + $4;
printf "%d %d %d %d %d\n", $1, $2, $3, $4, total; system("echo " total)}'

echo "$total"

if ["$total" -le "20" ]; then
pwd

fi

exit 0

ttest.dat內容
10 10 10 10
11 11 11 11
5 5 5 1

為什麼awk執行完後 我的total裡面就什麼都沒有了。
要怎麼修改我的pwd才會執行到?
謝謝

--
Tags: Linux

All Comments

Thomas avatar
By Thomas
at 2012-04-09T16:43
awk的變數,shell變數,環境變數三者各有scope
Valerie avatar
By Valerie
at 2012-04-12T17:19
total沒有被初始化所以echo不出來
而你想要的結果只有在awk中有效
Caroline avatar
By Caroline
at 2012-04-16T15:48
那我要怎麼修改呢?
Suhail Hany avatar
By Suhail Hany
at 2012-04-20T17:54
比較簡單的方法是將if那部份移到awk中去做
Ethan avatar
By Ethan
at 2012-04-23T03:04
你這個程式其實可以完全在 awk 中完成~
Skylar Davis avatar
By Skylar Davis
at 2012-04-27T01:33
ok thanks

dl.google.com的更新變很慢

Noah avatar
By Noah
at 2012-04-06T05:21
我是用 Linux mint 最近用 apt-get update 變得超級慢 後來看了一下 似乎是 dl.google.com 的問題 我看好像很多人都跟我有一樣的情形 http://code.google.com/p/chromium/issues/detail?id=93409 會用到是因為裝 ...

glibc

Mason avatar
By Mason
at 2012-04-05T21:41
我自己寫的包含自訂class的c++程式,test_file 執行到new該class時,會發生memory error Error msg如下: *** glibc detected *** ~/test_dir/test_file: malloc(): memory corruption: 0x086 ...

在mac的parallels安裝B2D問題..

Hedda avatar
By Hedda
at 2012-04-05T21:08
我在mac上的虛擬機器安裝B2D server,一進去xwindow他整個圖示字體什麼的,小的 非常恐怖,看到眼睛脫窗也看不出甚麼東西,重新安裝好幾次選哪個解析度都是一樣情況 。 請問有解決的辦法嗎? - ...

C compiler cannot create executables

Cara avatar
By Cara
at 2012-04-05T20:23
小弟我最近在mac 上裝 PECL 執行./configure 時 出現了下面的error 有google了一下 但還是不知道如何解決 checking for Cygwin environment... no checking for mingw32 environment... no ...

關於光碟中的autorun.sh

Bethany avatar
By Bethany
at 2012-04-05T18:12
小弟目前在製作光碟自動執行的功能, 在linux下發現可以使用autorun.sh在光碟中自動執行 當我讓系統自動掛載時,系統有詢問是否要自動執行, 但是,當我點選執行時卻又發生錯誤 錯誤訊息為 自動執行軟體錯誤 找不到自動執行的程式 但是我將autorun.sh的內容直接單 ...