LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-24-2011, 09:55 AM   #1
MarcosPauloBR
Member
 
Registered: Feb 2011
Location: Santa Catarina - Brazil
Distribution: Slackware
Posts: 129

Rep: Reputation: 3
Confusion on get the first parameter on Shell Script


Hi people!

I'm getting a error message on this script
Code:
if [ $1 -e '1' ]
then envia_arquivo
else 
       if [ $1 -e 2 ]
        then echo 'Implementar!'
        else echo 'Os parametros devem ser 1(para envio de arquivos) ou 2(para receber arquivos)'
             exit 1
       fi
fi
when o call this file with 1 as the parameter, I get this message:

./envio.sh: line 25: [: -e: binary operator expected
./envio.sh: line 28: [: -e: binary operator expected

OBS: There are more lines, because of this the line number are higher then the script.

I'm doing anything wrong?

Thanks!!
 
Old 03-24-2011, 10:01 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
The -e flag refers to FILES. You could do it as follows:

Code:
if [ "$1" != "" ]; then
    echo "Positional paremeter exists"
else
    echo "Positional Parameter $1 does not exist"
fi
 
Old 03-24-2011, 10:05 AM   #3
MarcosPauloBR
Member
 
Registered: Feb 2011
Location: Santa Catarina - Brazil
Distribution: Slackware
Posts: 129

Original Poster
Rep: Reputation: 3
I need to compare the parameter with a number.

How can I do this??

Thanks for your time!!
 
Old 03-24-2011, 10:21 AM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
What if you modify the script I posted above and include the number in " "?
 
Old 03-24-2011, 10:28 AM   #5
MarcosPauloBR
Member
 
Registered: Feb 2011
Location: Santa Catarina - Brazil
Distribution: Slackware
Posts: 129

Original Poster
Rep: Reputation: 3
I did it!

I modified to if [ $1 = '1'] and it works!

Thanks!
 
Old 03-25-2011, 01:25 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Actually, for numbers you should use
Code:
if [[ $1 -eq 1 ]]
strings use
Code:
if [[ $1 = "somestr" ]]
http://tldp.org/LDP/abs/html/comparison-ops.html
http://tldp.org/LDP/abs/html/fto.html
http://tldp.org/LDP/abs/html/testconstructs.html
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass command-line parameter to shell script? Kropotkin Linux - Newbie 12 07-25-2011 09:24 AM
Parameter to execute shell script on puppet client through Puppet server niraj.kumar Linux - Server 3 02-08-2011 09:01 PM
Writing a Shell Script with a Time Parameter Siva4Linux Linux - Wireless Networking 2 02-05-2007 06:56 AM
linux bash - how to use a dynamic parameter in shell parameter expansion expression nickleus Linux - General 2 08-21-2006 04:54 AM
How to change parameter values of a function in shell script? Bassam Programming 0 01-25-2004 09:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration