bash string comparison with nested variables -


so i'm quite new bash , im writing basic script run application utility me. want check output specific string response , log if has error. able script working if use line

if [[ $condition == *"added"* ]] ; 

as try exact comparision

if [[ "$condition" == "condition:${2} date:${3} added" ]] ; 

it not work though can see output correct. have feeling im comparing wrong or secrete characters being added bash function havent learned yet. appreciated.

update!

so feedback have been given have tried make code more clear , idea of raw string values are. far replying back. below updated script , output

#!/usr/bin/sh # script posts condition sent shout destination table # in ccm. used generate job_late incidents. # if error encountered logged in # job_late_error_log.txt file. # utility -> ctmcontb -add <condition name> <condition date> # condition format -> l@%%jobname-%%nodeid -> job_late format # $2 = l@%%jobname-%%nodeid $3 = <condition date> cmd_output=$(ctmcontb -add $2 $3) time_stamp=$(date) working_directory=/apps/ctm/devsv/scriptsadmin/do_condition/ error_file=job_late_error_log.txt write_file_to_location=$working_directory$error_file #if [[ $cmd_output == *"added"* ]] ; echo below hex output of "condition:${2} date:${3} added" echo "condition:${2} date:${3} added" | od -xc echo below command $cmd_output echo "$cmd_output" | od -xc cmd_ouput_no_space = "$(echo -e "${cmd_output}" | tr -d '[[:space:]]')" echo below command white spaces removed echo $cmd_ouput_no_space if [[ "$cmd_ouput_no_space" == "condition:${2} date:${3} added" ]] ;     echo $cmd_ouput_no_space     echo successfull ran util     exit 0 else  #   echo $cmd_ouput_no_space $time_stamp >> $write_file_to_location     echo $cmd_ouput_no_space      echo error occurred running util     exit 1 fi 

and output:

ctmtest1-tctmsv80 [9] job_late.sh ctmtest1 u350932-test2 0816 below hex output of condition:u350932-test2 date:0816 added 0000000     434f    4e44    4954    494f    4e3a    7533    3530    3933            c   o   n   d     t     o   n   :   u   3   5   0   9   3 0000020     322d    7465    7374    3220    4441    5445    3a30    3831            2   -   t   e   s   t   2       d     t   e   :   0   8   1 0000040     3620    6164    6465    640a            6         d   d   e   d  \n 0000050 below command condition:u350932-test2 date:0816 added 0000000     2043    4f4e    4449    5449    4f4e    3a75    3335    3039                c   o   n   d     t     o   n   :   u   3   5   0   9 0000020     3332    2d74    6573    7432    2044    4154    453a    3038            3   2   -   t   e   s   t   2       d     t   e   :   0   8 0000040     3136    2061    6464    6564    0a00            1   6         d   d   e   d  \n 0000051 job_late.sh[19]: cmd_ouput_no_space:  not found below command white spaces removed   error occurred running util 

im not familiar od -xc call looks values different make sense. not sure why though?

update 2:

so tried removing white spaces using line

cmd_ouput_no_space = "$(echo -e "${cmd_output}" | tr -d '[[:space:]]')" 

that found here:

how trim whitespace bash variable?

but doesn't seem work. have updated original script , ouput @ top of post errors im having.

there space before condition in captured cmd_output.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -