首页 > 系统服务 > 详细

shell map

时间:2021-04-02 12:25:06      阅读:22      评论:0      收藏:0      [点我收藏+]
#!/bin/bash

# Only 1 parameter !
if [ $# != 2 ];then
        echo " Usage: .\read.sh filename parameter !";
    exit
fi

# check the file !
if ! [ -f $1 ];then
    echo "file does not exist!"
    exit
elif ! [ -r $1 ];then
    echo "file can not be read !"
    exit
fi

# PRESS ANY KEY TO CONTITUE !
read -p "begin to read $1 "

# set IFS="\n" , read $1 file per line !
IFS="
"

# i is the line number
i=1
for line in `cat $1`
do
    echo line $i:$line
    let "i=$i+1"
done

declare -A myMap

IFS=" "
while read key val
do
    echo 键=$key 值=$val
    myMap[$key]=$val
done <  $1
echo ${myMap[$2"_user"]}
echo ${!myMap[@]}
echo "Finished reading file by line ! "

  

shell map

原文:https://www.cnblogs.com/Babylon/p/14609778.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!