syntax for CAT in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting syntax for CAT in ksh
# 1  
Old 01-07-2009
syntax for CAT in ksh

Just want to ask if the below code is correct;

if [ {cat out.txt |wc -l} -eq 0 ]; then
echo "No log found from " $data
exit 0
else
cat out.txt
fi

this is to test if the content of out.txt is 0 then message appear that there is no log. Is this correct?
# 2  
Old 01-07-2009
Use the test command with the -s option.

Regards
# 3  
Old 01-07-2009
Quote:
Originally Posted by harry0013
Just want to ask if the below code is correct;

You don't need to use cat with most commands; they take one or more filenames as arguments, and when they don't (as with tr), you can use redirection. With wc youcan use either, but the result is slightly different. In this case, you want redirection:

Code:
wc -l < out.txt

But you don't even need that. To test whether the file has a non-zero length use the -s option to test:

Code:
if [ -s out.txt ]; then
   cat out.txt
else
  echo "No log found from " $data
  exit 0
fi

Quote:
Code:
  echo "No log found from " $data
  exit 0
else
  cat out.txt
fi

this is to test if the content of out.txt is 0 then message appear that there is no log.
# 4  
Old 01-07-2009
Thank you all. Its working now using -s option.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with ksh syntax error Unexpected Fi

Issue resolved, thanks (6 Replies)
Discussion started by: dangell82
6 Replies

2. Shell Programming and Scripting

syntax of if condition in ksh is wrong

The syntax of 'if' conditionals in bash and ksh seems different. I am trying to check for a particular version using 'if' in ksh. This very simple syntax gives syntax error. I have tried many variants, but no go. Please correct the syntax. Later I will expand it to 'if' and 'else'. #!/bin/ksh... (8 Replies)
Discussion started by: nivedhitha
8 Replies

3. Shell Programming and Scripting

KSH syntax error

Hi all, Anyone know why I get the error below under ksh? $ EXCLUDES=( $(< "$EXCLUDES_FILE") ) sh: syntax error: `(' unexpected I'm trying to use the above line in a script and it's not working. The guy that gave me the script was running in a linux environment, so I'm thinking this might... (1 Reply)
Discussion started by: mmw
1 Replies

4. Shell Programming and Scripting

complex if statement syntax without using 'if ..' keyword in ksh.

It saves me lot of typing and space/lines when I do not use full 'if' keyword and construct, instead use .. && <statement> || <statement> that perfectly replaces.. if ; then <statement> else <statement> fi Can I use following syntax when I want to add multiple statements under 'if'... (4 Replies)
Discussion started by: kchinnam
4 Replies

5. Shell Programming and Scripting

ksh syntax error: `(' unexpected

So I am trying to convert my bash script into ksh, and this is what I have in the file so far: #!/bin/ksh login() { if then sendcmd BETA else sendcmd "$(xxd -c 32 -g 0 ${ZETA_ZETA} | awk '{print $2}')" fi } But when I run it: $ ./test.sh ... (1 Reply)
Discussion started by: guitarscn
1 Replies

6. Shell Programming and Scripting

KSH - different syntax for function

Hi, I wanted to know what's the difference between the below two syntax used for writing ksh function: e.g. 1 ------ function fn1 { echo "Hello World" } e.g. 2 ------ fn1 () { echo "Hello World" } (4 Replies)
Discussion started by: dips_ag
4 Replies

7. Shell Programming and Scripting

Checking ksh script syntax

To check a bash script syntax without executing it we use: bash -n scriptname What should be the equivalent command for checking a ksh script? (8 Replies)
Discussion started by: proactiveaditya
8 Replies

8. Shell Programming and Scripting

syntax issue in ksh file

Hi all, I am struck with syntax for long time, Need to purge some lines from given file Not able to use value of $x Example of ksh script... Facing some syntax issue. Have Tried ‘with single , double ,backtick “” ` and \ escape character , doesn't seem to work. <line 1> echo $x #... (2 Replies)
Discussion started by: manav666
2 Replies

9. Shell Programming and Scripting

KSH CAT Two files into one

Quick question, File A has one line (10 charachters), File B has one line (10 charachters). how do a concat these two files together to produce a file (File C) that has the contents of Files A + B together onto one line of 20 Charachters if I use: cat FileA FileB > FileC I get the... (5 Replies)
Discussion started by: kshelluser
5 Replies

10. Shell Programming and Scripting

ksh syntax explanation - from mimetool

Hi I got this part of the script from the mimetool by Perderabo. I have difficulty in decyphering the syntax specially lines 4,5 & 9. Also the test condition in line 3. Could someone help me on this please. -------------------------------------- pwentry=$(grep "^$(logname):" /etc/paswd)... (2 Replies)
Discussion started by: chaandana
2 Replies
Login or Register to Ask a Question