![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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 Code:
./1.ksh dm5admin Last edited by ranj@chn; 04-03-2008 at 04:50 AM.. Reason: typo |
|
||||
|
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. |
|
||||
|
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 |
|
||||
|
$#
$# 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 |
|
||||
|
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.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|