shell
  • csh
  • 2016-10-04 54 views 0 likes 
    0

    如何使用csh腳本讀取屬性文件?使用csh腳本讀取屬性文件

    當我GOOGLE時,我看到的只是bash腳本。

    目前我正在用的就是

    #!/bin/csh 
    
    set config_file=$1 
    
    echo "Configuration at : $config_file" 
    
    set server=`grep -i 'server' $config_file | cut -f2 -d'='` 
    set port=`grep -i 'port' $config_file | cut -f2 -d'='` 
    
    if ("$port" == "") then 
         set port=9000 
    endif 
    

    我的屬性文件是

    server=192.168.1.20 
    port=8081 
    

    它的正常工作。但是,如果任何財產被評論,它仍然讀取價值。

    server=192.168.1.20 
    #port=8081 
    

    在第二種情況下,端口的最終值爲8081而不是9000。

    回答

    1

    awk如下;

    awk '$0 !~ /^#/'意味着,如果端口未行以#

    #!/bin/csh 
    set config_file=$1 
    echo "Configuration at : $config_file" 
    set server=`grep -i 'server' $config_file | cut -f2 -d'='` 
    set port = `grep -i 'port' $config_file | awk '$0 !~ /^#/' | cut -f2 -d'='` 
    if ("$port" == "") then 
         set port=9000 
    endif 
    
    開始設置
    相關問題