2017-08-24 29 views
0

我的腳本中有以下代碼。還有50個像這樣的命令:處理shell腳本中的常量和變量

"SELECT date, count(*) FROM ttc_table....date_sub(current_date, **30**)" > **/path/location/file1.txt** 
"SELECT date, count(*) FROM ascc_table....date_sub(current_date, **30**)" > **/path/location/file2.txt** 
"SELECT date, count(*) FROM bmtc_table....date_sub(current_date, **30**)" > **/path/location/file3.txt** 

我想爲值30創建常量併爲filepath指定一個變量。

什麼是最好的方法?

+0

看看這個:http://www.compciv.org/topics/bash/variables-and-substitution/或者在SO上搜索「* bash變量替換*」。 – Arminius

回答

0

@Arminius的評論實際上回答了一半的問題,一個關於變量的問題,具體到bash

既然您已將問題標記爲shell,我假設您正在搜索一個適用於POSIX shell的答案。這意味着:

(1)儘管Arminius在文檔中解釋了許多可變的替換,但在POSIX shell中也是如此,請注意並非所有變量都可以。

(2)您還詢問了有關定義常量的問題。在POSIX shell中,AFIK無法定義常量。如果你真的需要這個,你必須切換到不同的shell - 例如Zsh或bash。請注意,在這些shell中,常量實際上被稱爲只讀變量