op is invalid


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting op is invalid
# 1  
Old 08-29-2009
op is invalid

In the following code

Code:
a=
[ -n $a ]
echo $?
[ -z $a ]
echo $?

Why the op is

Quote:
0
0
# 2  
Old 08-29-2009
Quote the variable and you'll get the correct result.
# 3  
Old 08-29-2009
The -n test requires that the string be quoted within the test brackets. Other test operators, or using no operator (implied -n), will generally work as you would expect without quoted strings. But, to be safe, it is generally recommended that you always quote your strings when testing.

Code:
a=
[ -n $a ]
echo $?
[ $a ]
echo $?

Output:
Code:
0
1

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Crontab invalid account

Need assistance in crontab issue . Issue is user account getting error "Warning - Invalid account: 'cyborg' not allowed to execute cronjobs" on Solaris 11 Couple of steps I tried 1. Added user to /etc/cron.d/cron.allow 2. Checked if the account is locked *LK* . It is not locked 3. No log... (2 Replies)
Discussion started by: ajayram_arya
2 Replies

2. UNIX for Advanced & Expert Users

Invalid date

Hi, I have a function to calculate "yesterday" in format YYYYMMDD: desa_ev9 # date +"%Y%m%d" --date "-1 day 20180701" 20180630 desa_ev9 # date +"%Y%m%d" --date "-1 day 20180720" 20180719 desa_ev9 # date +"%Y%m%d" --date "-1 day 20190101" 20181231 desa_ev9 # date +"%Y%m%d" --date "-1... (2 Replies)
Discussion started by: augreen
2 Replies

3. Linux

Invalid Character

Hi, I am using a Perl script to generate a report file in Linux server. When my input data contains an invalid character which looks like hyphen after that my program is printing junk values in the report. Why that symbol is causing issue and is there a way to tell the server that this is a valid... (1 Reply)
Discussion started by: lawrance_ps
1 Replies

4. Shell Programming and Scripting

?Invalid Command

when i am executing the script i am getting ?Invalid command though the script is right. Could any one please let me know how to overcome this problem. Urgent Please Thanks a lot in advance (2 Replies)
Discussion started by: Olivia
2 Replies

5. Shell Programming and Scripting

Invalid Command Name

I have telnet to a machine and executed some commands in it. pls see below : #!/usr/bin/expect spawn telnet 170.10.11.1 2100 expect "login:" send username\r expect "password:" send password\r expect "$" send "touch filetest\r" expect "$" send exit\r expect... (3 Replies)
Discussion started by: sudharsan23
3 Replies

6. Solaris

id: invalid user name

Hello, We run solaris 8 with nis+, when I do niscat, I can see the user's information, but when I do id from the domain it is saying invalid user. What may be the problem? id: invalid user name: "abyu789" (1 Reply)
Discussion started by: mokkan
1 Replies

7. Shell Programming and Scripting

SFTP Invalid IP

Hi, I have an SFTP script which is called from another run script: When the SFTP process is run we passed through an invalid ip address to check the error logging and to ensure everything is working as expected. Below is a sample of the code in the script: $RUNSOCKS... (2 Replies)
Discussion started by: ronnie_uk
2 Replies

8. Post Here to Contact Site Administrators and Moderators

invalid link

i follow on the https://www.unix.com/cfmgoogle.php?cx=partner-pub-6323928554267084%3Absye1r5tx7j&cof=FORID%3A10&q=solaris&sa=Search#907 https://www.unix.com/sun-solaris/ (4 Replies)
Discussion started by: Hank
4 Replies
Login or Register to Ask a Question