Awk method assigned to the shell variable
Method three: I use is this: the results directly into an array
redis_list=$($redis_comm -p 9001 cluster nodes | grep master | awk '{print $2}' | awk -F['@'] '{print $1}')
## sample 1
sid_list = ($ (ps -ef | grep ora_pmon | grep -v grip | awk '{print $ 8}' | AWK -F_ '{print $ 3}'))
#echo $ {sid_list [@]}
USER_LIST = ($ (ps -ef | grep ora_pmon | grep -v grip | awk '{print $ 1}'))
#echo $ {USER_LIST [@]}
for i in $(seq 0 ${#sid_list[@]}); do
sid=${sid_list[$i]}
user=${user_list[$i]}
echo $sid
echo $user
# do something....
done
##sample 2
a=("Fdf" "df" "fd")
for str in ${a[@]};do
echo $str
done
a=("Fdf" "df" "fd")
for i in $(seq 0 ${a[@]}); do
e=${variable[$i]}
echo $e
done
----------------
thank zzhongcy test_sharing
Disclaimer: This article is the original article CSDN bloggers "zzhongcy", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/zzhongcy/article/details/100523255
Thanks touch_future
linux shell is defined in the array and methods for loop through
Updated: June 20, 2018 09:50:23 Author: touch_future I want to comment
Thank Hillsborough good magic
https://blog.csdn.net/yaoxiaofeng_000/article/details/52790091?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
So this is a utf-8 format encoding problem
switch with the unix file into notepad ++ and replaced without utf-8 encoded BOM (UTF-8 coding) encoding format file