If statement UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If statement UNIX
# 1  
Old 10-17-2013
If statement UNIX

Hi,

I have an if-else statement here but I am receiving some error.

Code:
if [ -f /dev/myfolder/someword* | grep "Oct 02" ]; then
          ls -lrt /dev/myfolder/someword* | grep "Oct 02" | awk '{print $9}' 
else
          echo "some message"
fi

It does go to the else and execute the command there but I am still receiving this error.

Code:
./myscript.ksh[112]: test: 0403-021 A ] character is missing.
grep: 0652-033 Cannot open ].

What is wrong with my code?

Thanks!
# 2  
Old 10-17-2013
Code:
[ -f /dev/myfolder/someword*Oct\ 02* ]

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 10-17-2013
does this command able to determine when a file is created?

Code:
 [ -f /dev/myfolder/someword* ]

# 4  
Old 10-17-2013
A test -f must have exactly one argument.
Try this instead
Code:
files=`
ls -lrt /dev/myfolder/someword* | grep "Oct 02" |
awk '{print $9}'
`
if [ -n "$files" ]
then
   echo "$files"
else
   echo "some message"
fi


Last edited by MadeInGermany; 10-17-2013 at 10:54 PM..
This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 10-17-2013
It worked perfectly!

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Shell Programming and Scripting

Case statement in UNIX shell script

have written the below code to check whether the string received from user is a file name or dir using case statement, but its going into default case*). #!/bin/sh #Get a string from user and check whether its a existing filename or not rm str2 rm str3 echo "enter a file \c" read fil... (8 Replies)
Discussion started by: Mohan0509
8 Replies

3. Shell Programming and Scripting

Why statement works in LINUX and not UNIX?

Hello, I have a ksh script that uses code below. For some reason it works under linux but fails in unix. Any idea why? if ]; then ... Thanks (9 Replies)
Discussion started by: rdogadin
9 Replies

4. Shell Programming and Scripting

UNIX variable to SQL statement

The following is my script : #!/bin/bash echo "please give app_instance_id" read app_instance_id echo "id is $app_instance_id" export app_id=app_instance_id sqlplus -s nnviewer/lookup@//nasolora008.enterprisenet.org:1521/LOAD3 @test.sql<<EOF SPOOL /home/tibco/MCH/Data/qa/raak/name.xls... (4 Replies)
Discussion started by: raakeshr
4 Replies

5. UNIX for Dummies Questions & Answers

SQL statement is not work on unix script

Hi, I have the following basic script. However, the statement (line 5) is not work. The output data is not able to set my request format a30. Any advise? :mad: echo " Column filename format a30"|sqlplus4 echo Input file list to check: read filelist for file in `cat $filelist.txt` do... (1 Reply)
Discussion started by: happyv
1 Replies

6. UNIX for Dummies Questions & Answers

unix script with SQL statement problem

Hello, I have a script to get the information from database, however, it's look like the loop is not work, can someone help? :confused: echo Input file list to check: read filelist for file in 'cat $filelist.txt' do echo "select FILENAME from FILE_TABLE where filename like '${file}'%;" >>... (9 Replies)
Discussion started by: happyv
9 Replies

7. UNIX for Dummies Questions & Answers

Unix if statement

Hi, this is my first post. Although I have already read through the Forum Rules, please pardon me if I violate anything. I am trying to perform an if statement to check if a SET of files exist, and if they do, I would like to move them else where: $DIRECTORY_1 if ls filename*.txt then mv... (5 Replies)
Discussion started by: silvermission
5 Replies

8. UNIX for Dummies Questions & Answers

case statement in UNIX scripting (ksh)

Hi, I have a script like below : #!/bin/ksh echo "Do you want to export all docs ?" read alld echo "Do you want to export template or report only " read temr case && ] #arguments ;; case && ] #arguments ;; case && ] #arguments ;; (4 Replies)
Discussion started by: luna_soleil
4 Replies

9. UNIX for Dummies Questions & Answers

Perl / Interpret Unix If statement

Hi all, I am a newbie, so please let me know if there is a better way to do this. I coded a perl script, that scans a Unix script and picks out certain strings (strings that precede ".log"). However I want to limit the strings it picks up based on the "If statements" in the unix script. ... (0 Replies)
Discussion started by: syera123
0 Replies

10. Shell Programming and Scripting

How to convert unix command into Awk statement

Hi all, How can i use the below unix command in AWK . Can any one please suggest me how i can use. sed -e "s/which first.sh/which \$0/g" $shell > $shell.sal where $0=current program name(say current.sh) $shell=second.sh (1 Reply)
Discussion started by: krishna_gnv
1 Replies
Login or Register to Ask a Question