The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
command line arguments skooly5 Shell Programming and Scripting 1 04-07-2008 03:49 AM
arguments in command line rrs UNIX for Dummies Questions & Answers 6 07-28-2006 06:44 AM
command line arguments bankpro High Level Programming 3 02-02-2006 11:12 AM
Command Line Arguments roba909 UNIX for Dummies Questions & Answers 7 01-19-2006 01:46 PM
Parsing the command line arguments jayakhanna UNIX for Advanced & Expert Users 7 12-17-2003 07:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-03-2008
sunitachoudhury sunitachoudhury is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 36
Getting error in command line arguments

Hi,

When i am running the following script 1.sh (without giving the command line arguments) then i am getting the following error.

if [ $1 = dm5admin ]
then
echo "UID and PWD are correct"
elif [ $1 != dm5admin ]
then
echo "Either UID or PWD is wrong. Please check your UID and PWD"
else
echo "UID and PWD can't be blank"
exit;
fi


by running this 1.sh script i am getting the following error.

>1.sh
./1.sh: [: =: unary operator expected
./1.sh: [: !=: unary operator expected
UID and PWD can't be blank


Can anybody rectify this?????

Thanks.
  #2 (permalink)  
Old 04-03-2008
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
how are you executing?

Are you passing any arguments when running the script? The error points to no args passed to the script. Instead of the below logic, see if this helps -
Code:
if [[ $# -ne 1 ]]
then
 echo "Wrong usage"
 echo "USAGE: $0 [user-id]"
 exit -1
fi

#now check if the correct id was passed or not
if [[ $1 != "dm5admin" ]]
then
 echo "Invalid id passed"
 exit 2
fi

#carry on with processing now
Call the script as -
Code:
./1.ksh dm5admin

Last edited by ranj@chn; 04-03-2008 at 04:50 AM.. Reason: typo
  #3 (permalink)  
Old 04-03-2008
sunitachoudhury sunitachoudhury is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 36
yes i am running the script by using following arguments

1.sh dm5admin

but when i am not giving any arguments then i am getting error.

My requirement is that if i won't give any arguments the it will print

echo "UID can't be blank"


But when i am giving no arguments the i am getting the above error.
  #4 (permalink)  
Old 04-03-2008
sunitachoudhury sunitachoudhury is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 36
Hi ranj@chn,

thanks for your cooperate.

now i have two arguments like when i am trying to run the following

1.sh scu51 sunita
contents of 1.sh are
if [ $# -ne 1 ]
then
echo "UID cann't be blank"
exit -1
fi
if [ $# -ne 2 ]
then
echo "PWD cann't be blank"
exit -1
fi
if [[ $1 != "scu51" ]]
then
echo "Invalid UID passed"
exit 2
fi


then i am not getting my expecting results.

I am getting the following output

> 1.sh scu51 sunita
UID cann't be blank
  #5 (permalink)  
Old 04-03-2008
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
$#

$# tells the no of arguments passed to the script. Since, in your case you have passed 2 arguments, the first "if" condition gets satisfied and the error message gets thrown.

So, if you want to check that the script should take only 2 arguments, use the second if..then in your script.

Code:
if [[ $# -ne 2 ]]
then
..
fi
So, as you keep on adding parameters, change the count here. I hope it is clear now.
  #6 (permalink)  
Old 04-03-2008
sunitachoudhury sunitachoudhury is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 36
Hi ag79,

ya i also don't want to put my password.

Is there any way to hide the password. Actually i want to do the validation of my id and password before logining into FTP

Can anybody help me??????
  #7 (permalink)  
Old 04-03-2008
ag79 ag79 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 33
if you want to automate an ftp securely, you'll need non interactive authentication.
see man pages for sshd, ssh-keygen, and sftp for more details.

there are already several hundred pages on the web that'll help you set up secure ftp with public/private key authentication - use google.

of course there are other compromised solutions like denying read access to file(give only exec option), etc..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0