1. 程式人生 > >解決shell檔案讀取配置檔案key帶點號(.)的問題

解決shell檔案讀取配置檔案key帶點號(.)的問題

傳統source讀取方式

#application.properties

db.uat.user=user
db.uat.password=password
db.uat.url=https://www.baidu.com


#!/bin/sh

source "application.properties"

echo $db.uat.user
echo $db.uat.password

curl $db.uat.url

執行start.sh出現command not found.

解決方法:

改成如下方式讀取

#!/bin/sh

file="application.properties"

if [ -f "$file" ]
then
    echo "$file found."
    while IFS='=' read -r key value
    do
        key=$(echo $key | tr .-/ _ | tr -cd 'A-Za-z0-9_')
        if [ "$value"x != x ]; then      	    
		    eval ${key}=\${value}
        fi
    done < "$file"
else
	echo "$file not found."
fi

echo $db_uat_user
echo $db_uat_password

curl $db_uat_url

效果如下:

相關推薦

解決shell讀取配置檔案key(.)的問題

傳統source讀取方式 #application.properties db.uat.user=user db.uat.password=password db.uat.url=https://www.baidu.com #!/bin/sh source "application.pr

解決shell檔案讀取配置檔案key(.)的問題

傳統source讀取方式 #application.properties db.uat.user=user db.uat.password=password db.uat.url=https://www.baidu.com #!/bin/sh source "app

Linux Shell 指令碼讀取配置檔案

一、應用場景 為了靈活應用shell指令碼,適當的加入配置檔案,對於後期的維護和優化會有很大幫助。例如指令碼中使用的檔案/檔案路徑,都可以通過讀取配置檔案完成。 配置檔案 filename=boomlee 指令碼檔案 #!/bin/bash workdir=$(cd $(di

shell指令碼讀取配置檔案【有圖有真相】

配置檔案config.properties #以下是配置檔案內容,配置檔案檔名為config.properties username=jack password=33281   shell指令碼(指令碼名為 readConfig.sh) #!/bin/bash sour

java中使用log4j日誌檔案,讀取配置檔案的方式

publicvoid init() {//該方法必須在所有log4j使用前呼叫 最好時初始化時就呼叫執行 載入好配置                           Properties props =new Properties();//建立一個系統引數物件  

linux shell 讀取配置檔案

隨著linux接觸的越來越多,我們難免需要從一些配置檔案中進行讀取配置引數,linux中shell屬於指令碼型語言,讀取時沒有其它語言方便,特將用過的一種方式分享給大家 實戰程式碼: $ more a.txt name=hello world age=22 ip=192.168.

由於許可權不足而無法讀取配置檔案出現的HTTP 500.19解決辦法

無法訪問請求的頁面,因為該頁的相關配置資料無效。如下圖: 解決方法,到站點目錄的屬性,安全標籤,新增使用者(Everyone),並給修改許可權: 無法訪問請求的頁面,因為該頁的相關配置資料無效。 如下圖:  解決方法, 到站點目錄的屬性,安

解決IntelliJ IDEA無法讀取配置檔案的問題

idea對這些配置的檔案方式很明顯和eclipse是不同的。在idea中有一個 Content Roots的概念。需要為每一個folder配置相應的Content Roots。Content Roots包括resources、sources、tests等。 如圖所示:

Linux--shell 讀取配置檔案的方法

配置檔案config內容如下ID=123 IP=192.168.3.154 Name=test 方法一,利用sed解析文字,提取配置資訊 id=`sed '/^ID=/!d;s/.*=//' urfile` ip=`sed '/^IP=/!d;s/.*=/

IDEA下的MyBatis學習——讀取配置檔案失敗的解決方法

剛剛接觸了MyBatis,在寫”Hello World“入門程式時,總是報錯找不到對應的配置檔案,原本以為是路徑問題,因為視訊上是用的Eclipse,所以一直在換路徑也不明所以。 Debug了兩個小時後,在網上發現這是IDEA本身的問題。 E

MySQL-讀取配置檔案的工具類與測試

package JDBCUtil; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.ut

專案中讀取配置檔案的方式(二)

import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** 有時,需要配置檔案,配置檔案中儲存的內容是什麼 ? 儲存屬性 儲存一些經常

專案中常用的讀取配置檔案的方式(一)

package com.bjpowernode.demo01; import java.util.ResourceBundle; /** ResourceBundle讀取配置檔案 @author Administrator */ public clas

讀取配置檔案的工具類實現

/** * 讀取配置檔案的工具類 * */ public class ConfigManager { // 第一步:構建私有的靜態的例項 private static ConfigManager configManager; private static Properties pr

Django讀取配置檔案的機制解析

django.conf.init.py class LazySettings(LazyObject): """ A lazy proxy for either global Django settings or a custom settings object.

spring boot 入門1-----如何使用@Value註解讀取配置檔案以及使用@ConfigrationProperties註解

讀取.yml檔案屬性值的方式    1)如何將配置檔案中的屬性值與欄位匹配起來         @Value("${配置檔案中屬性的名}")       在application.yml檔案中   &n

Springboot讀取配置檔案、pom檔案及自定義配置檔案

前言 很多人都知道讀取配置檔案,這是初級做法,上升一點難度是使用java bean的方式讀取自定義配置檔案,但是大家很少有知道讀取pom檔案資訊,接下來我都會講到。 正文 筆者還是基於Spring Boot ::        (v1.5.8.RE

@PropertiesSource註解讀取配置檔案中的資料

這是properties配置檔案。 資料結構。   注入物件。 或者:   使用物件獲取屬性值。 或者:   瞭解:=========================================

springBoot 讀取配置檔案yml中的資訊

yml中自定義一些變數 var: analyze_url: test ocr_url: test microsoft_key: test 對映到類變數中 @Getter @Component public class varModel { @Value("${var.

Flash讀取配置檔案

  ① 先做全域性變數的宣告、但是不要給其賦值,在函式裡給其賦值 //炮彈速度 var paoDan_speed:int; var speed:int; var url=new URLRequest("info.xml"); //獲取一個xml檔案 var loa