bash運算問題 - Linux
By Adele
at 2021-07-24T05:28
at 2021-07-24T05:28
Table of Contents
各位千萬年薪大大好
小弟這裡有script的問題一直找不到解
問題1:
#!/bin/csh
set a = "16 + 1"
@ b = $a
echo $b
答案是17
set a = "16 * 1"
@ b = $a
echo $b
結果卻無解
後來發現帶有"*"的字元沒辦法存進變數a裡 (+ - / 皆可)
請問有什麼辦法可以解這題嗎?
問題2:
我有一個檔案test.txt
裡面只有一行 16 + 1 的字眼
#!/bin/csh
set a = `awk 'NR == 1 {print $0}' test.txt`
@ b = $a
echo $b
答案是17
但是改成如下寫法
@ b = `awk 'NR == 1 {print $0}' test.txt`
卻顯示 @: Badly formed number 錯誤
請問這兩邊差別在哪裡?
現在很尷尬的問題是假如test.txt裡是16 * 1
就無法將文本內容parsing到變數a裡(出現問題1的問題)
導致整個script無法處裡test.txt裡的乘法
百思不得其解
網路上的文章也查過了還是找不到解法
各位大大看我家搬到現在的份上
救救小弟吧(跪)
--
小弟這裡有script的問題一直找不到解
問題1:
#!/bin/csh
set a = "16 + 1"
@ b = $a
echo $b
答案是17
set a = "16 * 1"
@ b = $a
echo $b
結果卻無解
後來發現帶有"*"的字元沒辦法存進變數a裡 (+ - / 皆可)
請問有什麼辦法可以解這題嗎?
問題2:
我有一個檔案test.txt
裡面只有一行 16 + 1 的字眼
#!/bin/csh
set a = `awk 'NR == 1 {print $0}' test.txt`
@ b = $a
echo $b
答案是17
但是改成如下寫法
@ b = `awk 'NR == 1 {print $0}' test.txt`
卻顯示 @: Badly formed number 錯誤
請問這兩邊差別在哪裡?
現在很尷尬的問題是假如test.txt裡是16 * 1
就無法將文本內容parsing到變數a裡(出現問題1的問題)
導致整個script無法處裡test.txt裡的乘法
百思不得其解
網路上的文章也查過了還是找不到解法
各位大大看我家搬到現在的份上
救救小弟吧(跪)
--
Tags:
Linux
All Comments
By Emily
at 2021-07-24T21:36
at 2021-07-24T21:36
By Liam
at 2021-07-29T20:39
at 2021-07-29T20:39
By Skylar Davis
at 2021-08-03T19:01
at 2021-08-03T19:01
By Dinah
at 2021-08-05T06:39
at 2021-08-05T06:39
By Xanthe
at 2021-08-07T22:49
at 2021-08-07T22:49
By Belly
at 2021-08-08T06:37
at 2021-08-08T06:37
By Iris
at 2021-08-09T20:17
at 2021-08-09T20:17
By Skylar DavisLinda
at 2021-08-14T04:04
at 2021-08-14T04:04
By Kelly
at 2021-08-15T23:12
at 2021-08-15T23:12
By Daph Bay
at 2021-08-16T21:28
at 2021-08-16T21:28
By Kyle
at 2021-08-19T02:11
at 2021-08-19T02:11
By Dinah
at 2021-08-21T05:25
at 2021-08-21T05:25
Related Posts
崑大資傳系「鳥哥」架Linux免費教學網 人氣破四千萬
By Charlie
at 2021-07-24T01:43
at 2021-07-24T01:43
關於網路服務API的問題
By Necoo
at 2021-07-23T16:53
at 2021-07-23T16:53
Archlinux installation speedrun
By Dora
at 2021-07-22T21:50
at 2021-07-22T21:50
2021 07 ArchLinux 安裝紀錄
By Rachel
at 2021-07-20T02:36
at 2021-07-20T02:36
kali沒有wlan
By Carolina Franco
at 2021-07-19T11:54
at 2021-07-19T11:54