0
var2=$(echo "{$1}" | grep 'Objects that are still invalid after the validation:' | cut -d : -f2 | sed 's/ //g')
echo $var2

the above commandline substitution is not working ksh, the variable is blank each time, have tried below command too

var2="$(echo "{$1}" | grep 'Objects that are still invalid after the validation:' | cut -d : -f2 | sed 's/ //g')"
var2=`echo "{$1}" | grep 'Objects that are still invalid after the validation:' | cut -d : -f2 | sed 's/ //g'`
var2=`echo "$1" | grep 'Objects that are still invalid after the validation:' | cut -d : -f2 | sed 's/ //g'`

please hep me resolve the issue. The command is being used on remote server after ssh. The commands are working on the remote server if executed directly on the server without ssh.

pradeep panda
  • 65
  • 1
  • 10

1 Answers1

0

What is supposed to be in $1 ? First issue is that it ought to be written as either $1 or as ${1}. Writing it as {$1} is plain wrong.

Then there is the useless use of grep and cut. The following works:

var2=$(echo ${1} | sed -ne 's/ //g' -e 's/Objectsthatarestillinvalidafterthevalidation:\(.*\)/\1/p')
steviethecat
  • 870
  • 9
  • 14
  • $1 is an input string variable, have used {$1},"{$1}",$1 all the values and tried with simple commands but none of them are getting assigned to varibale. – pradeep panda Oct 29 '20 at 08:03
  • Then there must be something wrong with your input. The following works without problems: `x="Objects that are still invalid after the validation: foo bar" && var2=$(echo ${x} | sed -ne 's/ //g' -e 's/Objectsthatarestillinvalidafterthevalidation:\(.*\)/\1/p') && echo ${var2}`. Output: `foobar` – steviethecat Oct 29 '20 at 21:24