shell "if" condition not executed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell "if" condition not executed
# 1  
Old 12-15-2008
shell "if" condition not executed

Hi,

The below script should should create a file "COUNTFILE.log" if not found. But I am trying to run this and it is not creating the file .


#!/bin/sh
find . -name "COUNTFILE.log" > /dev/null 2>&1
if [ $? -eq 1 ]; then
echo 0> COUNTFILE.log
fi



Please advice why it is not creating the "COUNTFILE.log"

Regards
# 2  
Old 12-15-2008
Insert an
Code:
echo $?

right after the find. You will see that it is a zero because find encounters no error and exits successfull.

If you know the exact path where this file should be, maybe better test with something like
Code:
...
if [[ ! -e yourfile ]]; then
   touch yourfile
fi
...

Also it would be nice if you start to use [ code ] tags Smilie
# 3  
Old 12-15-2008
Kindly explain what are code tags...lot of experts are advising me to use code tags

Regards
# 4  
Old 12-15-2008
These are code-tags:

Code:
...

When writing your message, mark the code and press the little #-Button
in the toolbar. Its the fourth from the right.

HTH Chris
# 5  
Old 12-15-2008
ok ...you mean to say that my message should be presented like this.


Hi,

The below script should should create a file "COUNTFILE.log" if not found. But I am trying to run this and it is not creating the file .


Code:
#!/bin/sh
find . -name "COUNTFILE.log" > /dev/null 2>&1 
if [ $? -eq 1 ]; then 
     echo 0> COUNTFILE.log 
fi



Please advice why it is not creating the "COUNTFILE.log"

Regards

Last edited by zaxxon; 12-15-2008 at 09:03 AM.. Reason: Check now for code tags :)
# 6  
Old 12-15-2008
Great. Perhap it works this way:

Or remove the "x" in the tags: [xCODE] [x/CODE]
# 7  
Old 12-15-2008
I edited your post and added some so just edit it yourself again and you'll see them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

"Content-type: text/html No input file specified." Only in CRON but not when executed directly

Hi gang, I have the following code inside a the file script.sh #!/bin/bash todaysdate=$(date --date='7 day' +'%d') todaysmonth=$(date +'%m') todaysyear=$(date +'%Y') yahoodatestring=$todaysyear$todaysmonth$todaysdate nicedate=$(date --date='5 day' +'%A') nice="$nicedate,... (2 Replies)
Discussion started by: phpchick
2 Replies

3. Shell Programming and Scripting

Need help on " if condition" in shell

Is the below script/condition correct ? There are two square brackets, is it really required If everything seems ok, what would be the o/p ( 1 or 2 ) what exactly the condition is looking for ? answer = SK_BTS04A_hiQ_01b ...... ...... ...... elif *() ]]... (12 Replies)
Discussion started by: frintocf
12 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Linux

"at" command at RHEL 4.4 server is not being executed

I have Red Hat Linux 4.4 OS where i wanted to run a shell at a particular time using "at" command but the shell is not being executed and no error message is appearing on the screen. Please help Thanks in advance to all. (5 Replies)
Discussion started by: VISHAL SHARMA
5 Replies

6. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

10. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question