Empty Variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Empty Variable
# 1  
Old 03-10-2005
Empty Variable

I am trying to assign list of files that created that day to a variable 'filename'
filename=`ls -ltr |grep "Mar 6" | awk '{print$9}'`

If there are no files created that day, my script just hangs, i need help with some login here.

i am also trying to figure out a way to look for files that are created , say for ex: yesterday Mar 9. I am trying with

DATE=`date +%b`
DATE1=`date +%d`
tem="$DATE $DATE1"

If I give one more space it won't reconize date. Need help

Thanks,
Gundu
# 2  
Old 03-10-2005
You need to post more of your script. I dont see why the code you posted would make the script hang.
# 3  
Old 03-10-2005
OK , the 1st part is fixed, i tried with string not null, and it is OK.

My next and big problem is DATE

When I do ls -ltr , I get

-rw-r--r-- 1 xxxxx xxxx 2428 Mar 9 16:13 auditabcd

I am trying to look for the files belong to current date. I declared as :

DATE=`date +%b`
DATE1=`date +%d`
tem="$DATE $DATE1"

If I give one more space it won't reconize date. Need help

Thanks,
Gundu
# 4  
Old 03-10-2005
Quote:
Originally Posted by gundu
OK , the 1st part is fixed, i tried with string not null, and it is OK.

My next and big problem is DATE

When I do ls -ltr , I get

-rw-r--r-- 1 xxxxx xxxx 2428 Mar 9 16:13 auditabcd

I am trying to look for the files belong to current date. I declared as :

DATE=`date +%b`
DATE1=`date +%d`
tem="$DATE $DATE1"

If I give one more space it won't reconize date. Need help

Thanks,
Gundu
Quote:
Originally Posted by man strftime
%d Day of month [1,31]; single digits are preceded by 0.
$ date
date
Thu Mar 9 17:13:57 EST 2005

$ date +%d
09

Last edited by vgersh99; 03-10-2005 at 06:38 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue using empty variable in grep command

Hi, I'm writing a shell script and trying to grep a variable value, it works fine as long as there is a value in /tmp/list.out which is captured in $DSK but sometimes the file tends to be empty and that is where I'm having an issue while using grep which returns nothing. I know I can use something... (15 Replies)
Discussion started by: mbak
15 Replies

2. Shell Programming and Scripting

Stupid question to check if variable is empty

Hi, I am simply trying to check if the variable is empty in the code below but it isn;t working. Anything that I might have missed here #Check if values in job card are not empty title=`cat $filename | grep "TITLE:" | cut -d ":" -f3` if ] then echo "10:Title Empty" ":Fail">> $rptfile... (13 Replies)
Discussion started by: nua7
13 Replies

3. Shell Programming and Scripting

How to check whether a variable is empty or contains some value?

hi, i want to check whether a a variable contains some value or is empty in a shell script. so if the variable contains some value i want to do some job and if the variable doesnt contain any value then i need to skip that job. here is a sample script read_filenames.sh contains ... (5 Replies)
Discussion started by: Little
5 Replies

4. Shell Programming and Scripting

How do I change a variable to something only if it's empty?

I feel like it is just a matter of using the $ operators correctly, but I can't seem to get it... hostname="network" ip="192.168.1.1" netmask="" variables=( $hostname $ip $netmask ) for var in ${variables} do if ; then $var="--" fi done echo... (7 Replies)
Discussion started by: etranman1
7 Replies

5. Red Hat

Compare Empty Variable

Hello All, I am running the below code in my script. I want if jk is empty nothing should be appened to the file total_usage. but apparently its not happening.Kindy let me know how to do it. ################################### jk=`ps auxf |grep -w $inputline|tr -s " "|cut -d... (0 Replies)
Discussion started by: ajaincv
0 Replies

6. Shell Programming and Scripting

read variable from file show empty

Hi Folks, I am trying to read input from single line from a file and pass the read variable to one of the commands. However when I run the script it keeps the variable to be empty. I can however echo the variable ( but why it is empty when it goes to the command). Any help will be... (6 Replies)
Discussion started by: bhadu
6 Replies

7. Shell Programming and Scripting

How to check a variable for empty and a newline

I have a variable with a new line. I want to check this variable for empty or a new line Can anyone advise (4 Replies)
Discussion started by: Muthuraj K
4 Replies

8. Shell Programming and Scripting

How to check the variable is empty with spacing

How to check the variable is empty or not? aaa=" " how to check aaa variable is empty or just spacing? If only spacing inside.. it will asume it is empty. some are 6 spacing, or 8 spacing.. as long as variable is empty with spacing.. anyone can help me? (2 Replies)
Discussion started by: ryanW
2 Replies

9. Shell Programming and Scripting

How to check if two variable are empty strings at once? (bash)

I need to check if $1 or $2 are empty before continuing but I don't know if bash has any logic of the sort. This is what I'm looking for - except that "and" doesn't seem to work. if and ;then ... Thank you! :D (4 Replies)
Discussion started by: ph0enix
4 Replies

10. UNIX for Dummies Questions & Answers

Trying to capture empty variable.

sorry for the title of this thread- I figured out how to capture empty variable by using- if then ........ This thread originally had two parts in it (one for capturing empty variable and the other to get the date time in 14 char format). Once I figured out the solution for the first part... (6 Replies)
Discussion started by: radhika
6 Replies
Login or Register to Ask a Question