Returning a "0" if folder is empty


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Returning a "0" if folder is empty
# 1  
Old 06-01-2007
Returning a "0" if folder is empty

Hi All,

I am trying to force a "0" value if a folder is empty.
Is there any unix command i can make use of to force a "0" (zero) ?
i tried to use " grep -c * " but the error is " no match "
# 2  
Old 06-01-2007
Code:
$ grep -c "string" *
grep: 0652-033 Cannot open *.
$ echo $?
2

Code:
grep -c "string" *
if [ $? -eq 2 ]; then
    exit 0
fi

# 3  
Old 06-01-2007
Hi anbu,

Your code doesn;t seem to work.
Any other solution ?
# 4  
Old 06-01-2007
Hi anbu,


I tried to use " grep -c XXX /mycomp/unix/scripts/TEMP " where /mycomp/unix/scripts/TEMP is my empty folder with no files inside.

However, when there's files inside it will output a zero too.

PLs help

Last edited by Raynon; 06-01-2007 at 05:11 AM..
# 5  
Old 06-01-2007
hi,

try this.

ls -l folder_name > temp_file
x=`cat 2`
echo $x
grep -c "total 0" 2
echo $?
rm 2



Regards,
gander_ss
# 6  
Old 06-01-2007
hi,

try this.

ls -l folder_name > temp_file
x=`cat temp_file`
echo $x
grep -c "total 0" temp_file
echo $?
rm temp_file



Regards,
gander_ss
# 7  
Old 06-01-2007
Hi
What does $? represent ?
There's an error "Variable syntax" for this "$?".
Login or Register to Ask a Question

Previous Thread | Next Thread

8 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. Red Hat

Postfix keeps returning "Command time limit exceeded" message

We are having issues with our Postfix. The POP and IMAP services randomly stops working an sent e-mails return a "Command time limit exceeded". We've found out that running these command fix the problem: service cyrus-imapd stop rm /var/lib/imap/tls_sessions.db* rm... (2 Replies)
Discussion started by: GustavoAlvarado
2 Replies

3. 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

4. Shell Programming and Scripting

perl folder list with "..", without ".".

Hi Everyone, if my folder "foldera" inside has one file. so if i do if ($df =~ /^\./) { next; } then i will get ### filea ### if i want to have ### .. filea ### means also display the parent .., how should i modify the perl ~// in my code? Thanks ---------- Post updated... (6 Replies)
Discussion started by: jimmy_y
6 Replies

5. Shell Programming and Scripting

awk returning "[: ==: unary operator expected"

Hi All, I am new to shell scripting and right now I am just limited to using the pre-written scripts. I am in to Infrastructure management where we use different scripts to get the information passed on to the monitoring tools. I am trying to use this script to get the information about the... (2 Replies)
Discussion started by: theamrit
2 Replies

6. Shell Programming and Scripting

Argument ${1} returning "dev" [newbie inside]

I'm trying to build a korn shell script which will check some information located at a column of one .csv archive. The problem I'm having is that my script is not having the correct response: #!/bin/ksh i = 1 echo "Printing 1" echo "${1}" echo "Printing #" echo "${#i}" echo... (1 Reply)
Discussion started by: felipebb
1 Replies

7. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

8. Shell Programming and Scripting

check input = "empty" and "numeric"

Hi how to check input is "empty" and "numeric" in ksh? e.g: ./myscript.ksh k output show: invalid number input ./myscript.ksh output show: no input ./myscript.ksh 10 output show: input is numeric (6 Replies)
Discussion started by: geoffry
6 Replies
Login or Register to Ask a Question