Changeset 137


Ignore:
Timestamp:
Dec 28, 2017, 4:02:28 PM (6 years ago)
Author:
g7moreau
Message:
  • Define local variable and better mode implementation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tssh/tssh

    r136 r137  
    112112get_host_list () {
    113113   local cluster
     114   local default_mode=''
     115
     116   # set local mode
     117   if echo $1 | grep -- ^--mode=
     118   then
     119      default_mode=$(echo $1 | grep -- ^--mode= | cut -f 2 -d '=')
     120      shift
     121   fi
     122
    114123   for host in $*
    115124   do
    116       mode=""
    117       last_char="${host: -1}"
     125      local mode=${default_mode}
     126      local -r last_char="${host: -1}"
    118127      if [ "${last_char}" == "-" -o "${last_char}" == "+" ]
    119128      then
     
    123132
    124133      # short host without login part if any
    125       justhost=${host#*@}
     134      local -r justhost=${host#*@}
    126135     
    127136      cluster=$(grep "^${justhost}\b" ${HOME}/.csshrc | cut -f 2 -d '=')
     
    155164         # cluster, jump in a recursive mode
    156165         [ "${verbose}" == 'yes' ] && echo Warning: recursive mode for cluster ${cluster} with mode ${mode}
    157          cluster=$(get_host_list "${cluster}${mode}")
     166         cluster=$(get_host_list --mode=${mode} "${cluster}")
    158167      fi
    159168   done
     
    187196   fi
    188197
    189    session=$(shuf -n 1 /usr/share/dict/words | tr -cd "[:alpha:]")
     198   local -r session=$(shuf -n 1 /usr/share/dict/words | tr -cd "[:alpha:]")
    190199
    191200   IFS=$'\n' host=($(cat "/tmp/${base_path}/${f}"))
Note: See TracChangeset for help on using the changeset viewer.