linux - Shell script substring extraction and manipulation -


i able extract substring string; no matter syntax changes try (and i've tried many), unable enter if block in snippet though print out suggests client_name string matches expected 1 (attached output first echo). first echo prints anything. doing wrong here? ideas appreciated!

the idea if client named aa_nnnn, need extract aa , nnnn , check if aa matches known string (say "xx") , if does, then, calculate version nnnn , if version nnnn exceeds known version mmmm.

#! /bin/sh client=$1 ... client_name="${client:0:2}" client_version=2015 echo "before compare; client: $client_name; version: $client_version" if [ "$client_name" == "xx" ];    client_version="${client:3:4}"    echo "inside compare; client: $client_name; version: $client_version"    if [ $client_version -ge 2016 ];       ...    fi fi 

first echo output:

before compare; client: xx; version: 2015 

/bin/sh --version returns:

gnu bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu) copyright (c) 2009 free software foundation, inc. license gplv3+: gnu gpl version 3 or later <http://gnu.org/licenses/gpl.html>  free software; free change , redistribute it. there no warranty, extent permitted law. 

i got same result running code, removing quotes substring extraction (and replacing , : in second one) fixed it...

client_name=${client:0:2} 

...and...

client_version=${client:3:4} 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -