473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A file created in UNIX unwantedly

i=kk

if [ $i > 5 ]; then echo hi; else echo ii; fi

The aboce command returns the value "hi" and the most important thing is... it created a file of name 5. why does this happen???
Jul 12 '07 #1
2 1464
i=kk

if [ $i > 5 ]; then echo hi; else echo ii; fi

The aboce command returns the value "hi" and the most important thing is... it created a file of name 5. why does this happen???
Is the code only this? Or is it some other part of the code that creates the new file. Try removing the ;
Jul 12 '07 #2
prn
254 Expert 100+
i=kk

if [ $i > 5 ]; then echo hi; else echo ii; fi

The aboce command returns the value "hi" and the most important thing is... it created a file of name 5. why does this happen???
Hi sajithamol,

You have created a variable $i with a value of "kk". Next, you have told it (even though that's not what you thought you were telling it) to run "kk" and redirect the standard output of the command to a file called "5" and to test the exit status from that command to determine whether to echo "hi" or "ii". Since there is (presumably) no command "kk" the command "$i > 5" creates the file 5 but there is no output sent to the file, so file "5" is left empty. Furthermore, since "kk" is not the name of a command that your shell can find, the "exit status" is non-zero (127 for my shell, but it's possible that it is something else for you.

I may be misunderstanding what you are actually trying to do, but it looks awfully odd to me to be testing to see if a string "kk" is greater than an integer 5. Furthermore, if you are trying to do a string comparison, the only conditions that you can test are equal (=) and not equal (!=). OTOH, if you want an integer comparison, then you don't use ">". You should use "-gt". Check "man test" for more details.

I'm not sure which shell you are using, but it looks more like a Bourne-shell derivative than a C-shell derivative, so I'll give you the following example:
Expand|Select|Wrap|Line Numbers
  1. $ i=7
  2. $ export i
  3. $ echo $i
  4. 7
  5. $ if [ $i -gt 5 ]; then echo "hi"; else echo "ii"; fi
  6. hi
This does not create a file named "5". :)

Best Regards,
Paul
Jul 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
24
by: pristo | last post by:
hello All, how can i insert unique ID into binary file (that created by compiler)? (so after compiling i can to identify the src that i use) thx
11
by: Andre | last post by:
Hi, I have ASP.NET application running on standalone (not part of the domain) Windows 2003. I use forms authentication for my application. The problem I have is that I need to create and read...
2
by: Stan Sainte-Rose | last post by:
Hi, I need to read a kind of text file from vb.net I do know how to read a simple file, but this one seems to have special characters. Some characters appears like squares when open this file...
6
by: KoRnDragon | last post by:
I know about getlastmod() but is there one for created date? If not is there some other way of getting the created date of a file?
5
by: Grant Edwards | last post by:
When one open()s a file (that doesn't exist) for writing , how does one control that file's permissions (it's "mode" in Unix terms). -- Grant Edwards grante Yow! ...
4
by: Carl J. Van Arsdall | last post by:
I've been looking around the OS module and I haven't found anything useful yet. Does anyone know how to get the age of a file or directory in days? I'm using unix and don't seem to find anything...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.