Compare 1 with another string in bash

0 votes

I've spent 2 hours with an if statement, that never works like I want:

#should return true
if [ "$1" == "355258054414904" ]; then 

Here is the whole script:

#!/bin/bash

param=$1
INPUT=simu_900_imei_user_pass.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT ime not found"; exit 99; }
while read imei email pass 
do
    echo "First Parameter-IMEI: $1"
    if [ "$1" == "355258054414904" ]; then
        echo "GOOD"
    fi
done < $INPUT
IFS=$OLDIFS

This is the output of the script:

First Parameter-IMEI: 355258054414904
First Parameter-IMEI: 355258054414904
First Parameter-IMEI: 355258054414904

I have seen a lot of pages about the subject, but I can't make it work :(

EDIT: I Join the content of csv for better understanding ! Tx for your help !

4790057be1803096,user1,pass1
355258054414904,juju,capp
4790057be1803096,user2,pass2
358854053154579,user3,pass3
Jun 13 in Linux Administration by Rahul
• 3,380 points
11 views

1 answer to this question.

0 votes

The explanation $1 doesn't match is on the grounds that $1 implies the main boundary given to the content on the order line, while you believe it should match the principal field read from the record. That worth is in $imei.

You most likely implied:

on the off chance that [ "$imei" == "355258054414904" ];
    reverberation "Great"
fi
Since it is inside the circle where you read input record line by line.

To actually look at content of $1 use:

feline - vet <<< "$1"
UPDATE: To strip \r from $1 have this at top:

param=$(tr - d '\r' <<< "$1")
And afterward use "$param" in rest of your content.
answered Jun 13 by Korak
• 5,820 points

Related Questions In Linux Administration

0 votes
0 answers

Compare $1 with another string in bash

I've spent 2 hours with an if statement, that ...READ MORE

Jun 9 in Linux Administration by Rahul
• 3,380 points
8 views
0 votes
1 answer

Comparing two string variables in an 'if' statement in Bash

1. For string comparison, use: if [ "$s1" ...READ MORE

answered May 15, 2019 in Linux Administration by Shubham
• 13,490 points
349 views
0 votes
0 answers

How do I copy folder with files to another folder in Unix/Linux?

I am having some issues copying a ...READ MORE

Apr 13 in Linux Administration by Soham
• 8,730 points
19 views
0 votes
0 answers

How do I copy folder with files to another folder in Unix/Linux?

I am having some issues to copy ...READ MORE

Apr 21 in Linux Administration by Edureka
• 13,640 points
14 views
0 votes
0 answers

How to split a string into an array in Bash?

In a Bash script, I would like ...READ MORE

Jun 9 in Linux Administration by Rahul
• 3,380 points
14 views
0 votes
1 answer

How to take input from user in bash script?

You can use if-else branch to check ...READ MORE

answered Jan 31, 2019 in Linux Administration by Omkar
• 69,210 points
442 views
0 votes
1 answer

generating a list of files with their absolute path in Linux

If you find an absolute path to start with, ...READ MORE

answered May 16, 2019 in Linux Administration by Upasana
• 8,620 points
468 views
0 votes
1 answer

How to check if a string contains a substring in Bash?

You ought to recollect that shell prearranging ...READ MORE

answered May 27 in Linux Administration by Korak
• 5,820 points
19 views
0 votes
1 answer

Is there a limit on the number of words in bash command 'for file in words'?

Anyway, you need to print everything except ...READ MORE

answered May 27 in Linux Administration by Korak
• 5,820 points
18 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP