shell_script showing errors in the below mentioned script while executing in linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell_script showing errors in the below mentioned script while executing in linux
# 1  
Old 05-09-2012
shell_script showing errors in the below mentioned script while executing in linux

code:

Code:
IMAGE=$imgvalue;
 if [ $imgvalue :=1 ] 
then 
echo DO=ABC; 
elif [ $imgvalue :=2 ] 
then echo DO=ETC; 
elif [ $imgvalue :=3 ] 
then echo DO=XYZ; 
else 
echo "$imgvalue is unsupported"; 
exit 1; 
fi

in above script IMAGE=1 , IMAGE=2, IMAGE=3 whatever may be the value i have assigned it's showing only DO=ABC other conditions not working . any one pls check.

Last edited by Scrutinizer; 05-09-2012 at 03:45 AM.. Reason: code tags
# 2  
Old 05-09-2012
try this.
Code:
 
 
IMAGE=$imgvalue;
if [ "$imgvalue" -eq "1" ] 
then 
 echo DO=ABC; 
elif [ "$imgvalue" -eq "2" ] 
then 
 echo DO=ETC; 
elif [ "$imgvalue" -eq "3" ] 
then 
 echo DO=XYZ; 
else 
 echo "$imgvalue is unsupported"; 
 exit 1; 
fi

use [code] tag

https://www.unix.com/how-post-unix-li...code-tags.html
# 3  
Old 05-09-2012
Try:
Code:
case $imgvalue in
  1) echo DO=ABC;;
  2) echo DO=ETC;; 
  3) echo DO=XYZ;;
  *) echo "$imgvalue is unsupported" 
     exit 1
esac

# 4  
Old 05-09-2012
i have tried all possibilities and solutions mentioned above . it's not working .

can any one help the make script coding with the above requirement.only in below senario it's working and displaying DO=ABC for all inputs like IMAGE=1 or IMAGE=2 or IMAGE=3

Code:
IMAGE=$imgvalue;
if  [ $imgvalue =:1 ]
then
echo DO=ABC;
elif [ $imgvalue =:2 ]
then
echo DO=ETC;
elif [ $imgvalue =:3 ]
then
echo DO=XYZ;
else
    echo "$imgvalue is unsupported";
    exit 1; 
fi

# 5  
Old 05-09-2012
Quote:
Originally Posted by saku
i have tried all possibilities and solutions mentioned above . it's not working .
Hi,

I have tried the *two* solutions posted above and they both work. So can you be more specific about how it is not working.

If you are getting errors then post them.
# 6  
Old 05-09-2012
Quote:
Originally Posted by saku
i have tried all possibilities and solutions mentioned above . it's not working .

can any one help the make script coding with the above requirement.only in below senario it's working and displaying DO=ABC for all inputs like IMAGE=1 or IMAGE=2 or IMAGE=3

Code:
IMAGE=$imgvalue;
if  [ $imgvalue =:1 ]
then
echo DO=ABC;
elif [ $imgvalue =:2 ]
then
echo DO=ETC;
elif [ $imgvalue =:3 ]
then
echo DO=XYZ;
else
    echo "$imgvalue is unsupported";
    exit 1; 
fi

what is the problem?
Code:
imgvalue=$1
 if [ $imgvalue = 1 ]
then
echo DO=ABC
elif [ $imgvalue = 2 ]
then echo DO=ETC
elif [ $imgvalue = 3 ]
then echo DO=XYZ
else
echo "$imgvalue is unsupported"
exit 1
fi

Code:
# ./script 1
DO=ABC
# ./script 2
DO=ETC
# ./script 3
DO=XYZ
# ./script 4
4 is unsupported

# 7  
Old 05-09-2012
Hi,

cmd i am executing in linux:
and make is the file which having these changes.

$./make rel sapqe1 IMAGE=2
DO=ABC
$./make rel sapqe1 IMAGE=1
DO=ABC
$./make rel sapqe1 IMAGE=3
DO=ABC
$./make rel sapqe1 IMAGE=5
is unsupported

the problem is for every input of image only output i am getting DO=ABC

Code:
IMAGE=$imgvalue;
if  [ $imgvalue =:1 ]
then
echo DO=ABC;
elif [ $imgvalue =:2 ]
then
echo DO=ETC;
elif [ $imgvalue =:3 ]
then
echo DO=XYZ;
else
    echo "$imgvalue is unsupported";
    exit 1; 
fi


i am getting below error if i use if [ "$imgvalue" -eq "1" ] or if [ "$imgvalue" -eq "1" ]

error :
[: =: unary operator expected

Last edited by saku; 05-09-2012 at 05:33 AM.. Reason: want to edit the error
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

X11 errors on Solaris 10 - SL Console not showing up

Hi all, I have been administrating large backup environments for quite some time now, but I have never seen the types of errors I'm getting for a client I have in Asia, so I humbly appeal to your expertise in order to fix things. Set up: StreamLine 8500 library connected to a Solaris... (7 Replies)
Discussion started by: dilibau
7 Replies

2. Shell Programming and Scripting

Bash script errors when executing

I'm working on a script that will search through a directory for MKV files and remux them to MP4. I found a few other scripts around the net that do this, but they all have limitations that don't always get the job done. The main limitation I've found is that most scripts look for the video track... (2 Replies)
Discussion started by: rayne127
2 Replies

3. IP Networking

netstat showing lots of errors

Hi, I have a server which receive lots of events to it and when I do netstat -Ie1000g0, I'm seeing the errors as below. Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue e1000g0 1500 abc-1.com abc-1.com 3093708246 12757 92069412 0 0 0 If anyone could direct me to right... (3 Replies)
Discussion started by: mohzub
3 Replies

4. Shell Programming and Scripting

perl script to send an email executing with errors

Hello , i am using RHEL5 , i have got a perl script that executes and sends an email correctly if i run it with ./sendemail.sh command. This is the script below #! /usr/bin/perl use Net::SMTP; print "starting email send ."; $smtp = Net::SMTP->new("192.168.0.1");... (2 Replies)
Discussion started by: kabazzi
2 Replies

5. Linux

Error executing shell script in Linux

Hi, I have following shell script code : ------------------------------------------------------------------ #!/bin/bash SCRIPTS_DIR="/scriptsDir1" # tables login/password APIL_USER="uname/pswd" I2_USER="uname/pswd" # Database DB="db1" cd "$SCRIPTS_DIR/scriptsDir2" sqlplus... (1 Reply)
Discussion started by: Chaitrali
1 Replies

6. Shell Programming and Scripting

Error executing shell script in Linux

Hi, I have following shell script code : ------------------------------------------------------------------ #!/bin/bash SCRIPTS_DIR="/scriptsDir1" # tables login/password APIL_USER="uname/pswd" I2_USER="uname/pswd" # Database DB="db1" cd "$SCRIPTS_DIR/scriptsDir2" sqlplus... (2 Replies)
Discussion started by: Chaitrali
2 Replies

7. Shell Programming and Scripting

Showing errors when connecting to sqlplus in shell script

hi, I am trying to automate the compilation of procedures stored in .sql files in Unix. Is there any way in which we can sho err if there errors are raised in the compilation? I am using the following code to connect to the sqlplus sqlplus ${SQL_USER}/${SQL_PASSWORD} (5 Replies)
Discussion started by: silas.john
5 Replies

8. Shell Programming and Scripting

avoid displaying errors while executing a script

Hi all, I am running a script on bash shell, although it gives me the desired output, it displays some errors at the prompt like this directory doesnt exists unary operator etc etc Is there someway to avoid these errors ?? Its very annoying to have these errors while the script is... (4 Replies)
Discussion started by: vikas027
4 Replies

9. Shell Programming and Scripting

executing script not showing up in ps -efx

Hi everyone, here's my problem. I have a script that runs in a infinite loop, repeating the same action in another script every 10 minutes. We need to monitor whether or not this loop script is running and be able to kill it should the need arise. However, the name of the script does not show up... (6 Replies)
Discussion started by: herman404
6 Replies

10. Programming

Errors while executing a.out

Hi, I tried a simple hello.cc program in Unix. - Compiled with no errors - Created a.out successfully - While executing a.out, following error message appeared " ld.so.1:a.out fatal: libstdc++.so.2.10.0: Open failed: No such file or directory Killed" ... (1 Reply)
Discussion started by: nirthana
1 Replies
Login or Register to Ask a Question