Until the file extension matches


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Until the file extension matches
# 1  
Old 05-08-2008
Until the file extension matches

Hi All,

In my script I am trying to input data from user and I want the promt to appear again if the input data is not the one expected.

I tried something like this:

Code:
    echo " \n\n\t Enter the dump filename:\c";read dump
    pst=${dump##*.}
    until (test $pst = dmp)
        do
        echo " \n\n\t File extension not supported.!!!"
        echo " \n\n\t Enter the dump filename(eg:abc.dmp):\c"
        read dump
        done

but this not become false in any case and the prompt is apprearing again and again even if the condition is met(ie,if the user inputs .dmp file)
Where did I go wrong?
Sreejith_VK
# 2  
Old 05-08-2008
For string comparisons always put variables and strings in double qoutes.

like

until (test "$pst" = "dmp" )
# 3  
Old 05-08-2008
Thanks Ashish..
You are rt..
Sreejith_VK
# 4  
Old 05-08-2008
Use two =, not one:
Code:
until (test $pst == dmp)

BTW: to get answers it's generally a good idea to write which shell you're using
# 5  
Old 05-08-2008
Network Curious error

ksh. And
Quote:
==
is throwing the following error:

Quote:
==: unknown test operator
One more issue the "" worked only first time..
That is when I gave .dmp after accessing the script for the first time it goes through and comes to next step.
but when I gave .dmp again after an error it again throwed error Smilie
Sreejith_VK
# 6  
Old 05-08-2008
That is , If I commit a mistake once I dont get a chance to rectify the same.
Can any one please explain why is this so? Is this a property of "until"?
Sreejith_VK
# 7  
Old 05-08-2008
First thing is that you have a logic problem.
you're saying "until" $pst,
the you read & set dump, and then don't reset what pst is??
How would that ever work??

Code:
#!/usr/bin/ksh

print " \n\n\t Enter the dump filename:\c"; read dump
    pst=${dump##*.}

    until [ $pst = dmp ] 
    do
        print " \n\n\t File extension not supported.!!!"
        print " \n\n\t Enter the dump filename(eg:abc.dmp):\c"
        read dump
        pst=${dump##*.}
    done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

Required 3 lines above the file and below file when string matches

i had requirement like i need to get "error" line of above 3 and below 3 from a file .I tried with the below script.But it's not working. y='grep -n -i error /home/file.txt|cut -c1' echo $y head -$y /home/file.txt| tail -3 >tmp.txt tail -$y /home/file.txt head -3 >>tmp.txt (4 Replies)
Discussion started by: bhas85
4 Replies

3. Shell Programming and Scripting

FTP a file if the date matches

Hi, I am trying to write a script where I need to pull any file if the date is from yesterday. Can you please help me on how to check the dates for the files on the remote server? Please let me know for any questions. Thanks Ajay (4 Replies)
Discussion started by: ajayakunuri
4 Replies

4. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

5. Shell Programming and Scripting

Compare 2 files and print matches and non-matches in separate files

Hi all, I have two files, chap.txt and complex.txt. chap.txt looks like this: a d l m r k complex.txt looks like this: a c d e l m n j a d l p q r c p r m ......... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

6. Shell Programming and Scripting

regex matches from lines in file

Hello, I try to script something (bash-script) and can not find a way to get and store a match into a variable from a line in a file. grep isn't useful as the matches are not returned - just colored. I can't get 'expr' to work for me. Is it necessary to use a perl-script with regex instead? ... (7 Replies)
Discussion started by: daWonderer
7 Replies

7. UNIX for Dummies Questions & Answers

Pipe binary file matches grep results to file

I am using grep to match a pattern, but the output is strange. $ grep -r -o "pattern" * Gives me: Binary file foo1 matches Binary file foo2 matches Binary file foo3 matches To find the lines before/after, I then have to use the following on each file: $ strings foo1 | grep -A1 -B1... (0 Replies)
Discussion started by: chipperuga
0 Replies

8. UNIX for Dummies Questions & Answers

creating separate directories according to file extension and keeping file in different directory as

unix program to which a directory name will be passed as parameter. This directory will contain files with various extensions. This script will create directories with the names of the extention of the files and then put the files in the corresponding folder. All files which do not have any... (2 Replies)
Discussion started by: Deekay.p
2 Replies

9. Shell Programming and Scripting

get value that matches file name pattern

Hi I have files with names that contain the date in several formats as, YYYYMMDD, DD-MM-YY,DD.MM.YY or similar combinations. I know if a file fits in one pattern or other, but i donīt know how to extract the substring contained in the file that matches the pattern. For example, i know that ... (1 Reply)
Discussion started by: pjrm
1 Replies

10. Shell Programming and Scripting

find matches in file

Hi, im have log file ~100000 lines, 192.168.29.1 at 10/08/09 13:58:55 192.168.60.1 at 10/08/09 14:11:28 192.168.58.171 at 10/08/09 14:12:45 192.168.61.12 at 10/08/09 14:15:44 192.168.60.1 at 10/08/09 14:16:36 192.168.60.1 at 10/08/09 14:17:43 192.168.61.12 at 10/08/09 14:18:08... (9 Replies)
Discussion started by: Trump
9 Replies
Login or Register to Ask a Question