I have two string like this...


And I want to convert
a= 20180911183706376476
b= 2018082215261826182619

Can anyone please help me out?

closed as off-topic by womble Sep 11 '18 at 6:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – womble
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    You must include a space around both sides of the ] and [. And when writing shell scripts, it's good to use shellcheck. – Halfgaar Sep 11 '18 at 6:39
  • Now I want to convert [2018:08:22-15:26:18:26182619] to 2018082215261826182619. Can you please help me out? – Dipak Sep 14 '18 at 5:20
  • Welcome on the ServerFault. The command can be done with a="${a//[\[\]]/}", this removes all [ and ] from the variable $a. But it is not really a sysadm task, it is more like a little scripting trick. – peterh Sep 14 '18 at 6:20
  • Thanks.Getting error as ksh: a="${a//[\[\]]/}": bad substitution – Dipak Sep 14 '18 at 6:23

From the "test, [ -- condition evaluation utility" manpage (accessible using the command man [ or man test), the '-ne' option is used for comparing integers. Use the '=' operator for strings.

n1 -eq n2 True if the integers n1 and n2 are algebraically equal.

s1 = s2 True if the strings s1 and s2 are identical.

It's probably not a bad idea to quote the strings as well. Make sure to use double (or soft) quotes with variables.

if [ "$a" = "$b" ]
    #do something

Not the answer you're looking for? Browse other questions tagged or ask your own question.