Visit Our UNIX and Linux User Community


Some Problem with Korne Shell//


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Some Problem with Korne Shell//
# 1  
Old 12-05-2007
Some Problem with Korne Shell//

I am new to Korne Shell Scripting. Can someone help me with a Korne Shell which asks the user :-

1) to enter the name of a file when searching it recursively (using the find
command) in the home directory of this user.

2) for a date (format AAMMJJ) and a directory and then searches
recursively in this directory the list of files modified after the date
chosen.

Thanks,
Marconi.

Last edited by marconi; 12-05-2007 at 10:59 AM..
# 2  
Old 12-05-2007
Korne Shell

Any pointers will do.

Thanks.

Last edited by marconi; 12-05-2007 at 11:00 AM..
# 3  
Old 12-05-2007
Read the man-page of find ("man find") and a good book about ksh programming - Barry Rosenbergs "Hands-On KornShell93 Programming" (1998, Addison-Wesley) is IMHO the best and at the same time really funny to read.

This should answer all your homework questions you have.

(On a side note, learning how to edit your own postings using the "edit"-button instead of posting them anew would also help, but that will be left for the "advanced"-assignment of the computer science curriculum.)

bakunin
# 4  
Old 12-05-2007
Hi Everyone,

I have tried with the following Code for each of the following, but that does not seem to serve the purpose. Can someone give some pointers please.

1) A Korne Shell which asks the user to enter the name of a file when searching it
recursively (using the find command) in the home directory of this user.

#!/usr/bin/ksh
find * -type f -type d -path usr
if [ –a file ]
then
echo -n "Enter the file name"
fi


2) A Korne Shell which asks the user for a date (format AAMMJJ) and a directory and
then searches recursively in this directory the list of files modified after the date
chosen.

#!/usr/bin/ksh
if ['-d $1'+ 'date -t "%AA%MM%JJ"']
then
echo -n "find all files modified after the chosen date"
touch ' new date -nt "%AA%MM%JJ"
find * -type f -type new date

Thanks,
Marconi.
# 5  
Old 12-06-2007
*sigh*

I know, this is homework and i am aware that i am, by answering this thread, walking as thin a line as the OP. I hope to be able to push OP into the right direction without actually doing the assignment for the OP. (So much as a remark to the moderators here.)

Code:
#!/usr/bin/ksh
find * -type f -type d -path usr
if [ -a file ]
then
    echo -n "Enter the file name"
fi

The find-statement is wrong and you should indeed consult the manpage of find to out what exactly is wrong. There should even be some examples for correct find-statements there (manpages differ from system to system, on AIX there are examples, don't know about your system though). Try to analyze them.

in the line "if [ -a file ]" you refer to a STRING with the value "file" instead of a variable named "file". I suppose you intended the latter instead of the former. A variables value ins used in the Korn shell by a starting "$", like the following example:

Code:
file="/path/to/my/file"   # assign variable file a value

if [ -a $file ]    # test using the content of variable file

furthermore, read the man page of test (man test) to learn about possible test-conditions. "-a" is a binary AND and makes no sense whatsoever with a filename. An example for a "-a" which does make sense would be, if you have two test conditions and want to combine them, branching only when both are true:

if [ $a -gt 0 -a $b -le 5 ]

the first condition "$a -gt 0" is true when the content of variable a ("$a") is greater than ("-gt") zero, the second condition is true when the content of variable b ("$b") is lower or equal ("-le") to 5. The combined statement is "<condition1> -a <condition2>" and is true only if the first AND the second condition are both true.

I'll stop here and skip some other errors you made. I do hope that you understand i can't give you a complete Korn Shell lesson by just answering here in the forum. So again, my suggestion is you get yourself a copy of the book i mentioned in the first posting (or any other about the same subject according to your taste) and read it.

bakunin

Previous Thread | Next Thread
Test Your Knowledge in Computers #569
Difficulty: Medium
foreach loops are considered syntactic sugar.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problem with if in shell

Hi, My sheel script has below statement: if; then When I run iam getting the below error: -bash: syntax error near unexpected token `then' What is wrong with that statement: Plz help me. (2 Replies)
Discussion started by: pradeep_script
2 Replies

2. Shell Programming and Scripting

Finding modified File List after the chosen date in Korne Shell...

I am trying to write a Korne Shell asking the user for a date and a directory and then search recursively in this directory the list of files modified after the date chosen. But I am not getting good results when I Test it... #!/usr/bin/ksh echo "Enter a date (YYYYMMDD) " read date touch -t... (2 Replies)
Discussion started by: marconi
2 Replies

3. Shell Programming and Scripting

Korne Shell...

In Korne Shell Scripting, how to search recursively in a directory, the list of files modified after a given date .. Thanks in advance.. (1 Reply)
Discussion started by: marconi
1 Replies

4. Shell Programming and Scripting

Korne Shell Problem.

Hi Everyone, I have tried with the following Code for each of the following, but that does not seem to serve the purpose. Can someone give some pointers please. 1) A Korne Shell which asks the user to enter the name of a file when searching it recursively (using the find command) in the... (3 Replies)
Discussion started by: marconi
3 Replies

5. Shell Programming and Scripting

Fixed Length records- Korne Shell Program.

Hi, I need some help regarding in writing a Korne shell script, in determining the fixed length records in a data file. We have already utility in place, which does this work. The Code for this is as below. In the below $1 is the parameter passed to the script, which is the data file name. ... (4 Replies)
Discussion started by: nrajesh_2009
4 Replies

6. Shell Programming and Scripting

Problem in shell

hi, can any one tell a solution for the following : I want to append 10 spaces and a string say "ok" to 12 digit number which is stored in a varialbe & display using shell script. (1 Reply)
Discussion started by: Sandeep Kale
1 Replies

7. Shell Programming and Scripting

GOTO LOOP in KORNE SHELL

All Please help to provide "goto" functionality in KORN shell script. ex: 1: Command Process some command if check some variable true goto 1 else process some other Please help to implement this example in korne... (1 Reply)
Discussion started by: DeepakXavier
1 Replies

8. Shell Programming and Scripting

Mailing in Korne shell

All Iam using Korne shell in AIX OS. Can u give me the syntax to send a mail. Thanx in advance Regards Deepak (5 Replies)
Discussion started by: DeepakXavier
5 Replies

9. Shell Programming and Scripting

Korne Script for format file

Hi All, I am not too familiar with Korne script so I need as much help as possible on this ;) What I want to do is: from the excel file on my computer, I want to take certain field from this xls file and put it in txt or cvs format in specific width column. Then fpt this file into the server. ... (51 Replies)
Discussion started by: CamTu
51 Replies

10. UNIX for Dummies Questions & Answers

shell problem

&& set -x && echo "enter tablespace_end_backup" >&2 Can you tell me what's mean above? thanx (1 Reply)
Discussion started by: Lee
1 Replies

Featured Tech Videos