Using "if -e" with wildcard in csh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using "if -e" with wildcard in csh
# 1  
Old 11-14-2011
Question Using "if -e" with wildcard in csh

Hi Gurus,

In ksh we can check the existance of a file using wild card like ...

if [ -f /home/dbadm/clients/blocked/saltlake.txt.* ]

But in csh is there something like this ??? I have tried to use the following...

if -e /home/dbadm/client1/emailblocked/ludhiana5.txt.* then

But its getting failed and giving me the following error...
f -e /home/dbadm/client1/emailblocked/ludhiana5.txt.* then
/home/dbadm/client1/emailblocked/ludhiana5.txt.*: No match.

Could any one give me a hand on how to check filename.* using if statement in csh please ?

Regards...
# 2  
Old 11-14-2011
A quick read of the csh manpage yields:
Code:
set nonomatch

needs to occur before your if statement.
# 3  
Old 11-14-2011
Quote:
Originally Posted by sraj142
Hi Gurus,

In ksh we can check the existance of a file using wild card like ...

if [ -f /home/dbadm/clients/blocked/saltlake.txt.* ]

But in csh is there something like this ??? I have tried to use the following...

if -e /home/dbadm/client1/emailblocked/ludhiana5.txt.* then

But its getting failed and giving me the following error...
f -e /home/dbadm/client1/emailblocked/ludhiana5.txt.* then
/home/dbadm/client1/emailblocked/ludhiana5.txt.*: No match.

Could any one give me a hand on how to check filename.* using if statement in csh please ?

Regards...
* be sure there are files that match your pattern (ludhiana5.txt.*)
* try @m.d.ludwig's advice if there are files in there.
# 4  
Old 11-14-2011
Quote:
Originally Posted by sraj142
Hi Gurus,

In ksh we can check the existance of a file using wild card like ...

if [ -f /home/dbadm/clients/blocked/saltlake.txt.* ]
No, you can't. If there's more than one file that matches saltlake.txt.*, your program will have syntax errors.
# 5  
Old 11-15-2011
Of course, the fun really begins if the filename contains meta-characters ("saltlake.txt.*"), whitespace (or anything in ${IFS}) or other syntactical sugar

"Quotes are your friend"
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Advanced & Expert Users

"GET" command retrieves multiple files while using wildcard

Hi All I am using GNU/Linux This is regarding the get command to retrieve files (filename with wild card characters) from remote server. I thought Get command can retrieve only 1 file irrespective of the files it has on the remote server And it is the function of mget to retrieve all... (7 Replies)
Discussion started by: sparks
7 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. UNIX for Dummies Questions & Answers

Problem with sed wildcard "*"

Hi All, can you help me with "*" wildcard character in sed, i am a bit confused. I am going through a reference and found that below code sed -n '/a*c/' file will also return a line that contain the string output : close the window properly how is that possible when there is no "a"... (11 Replies)
Discussion started by: mukulverma2408
11 Replies

5. Shell Programming and Scripting

Translate wildcard-char "*"

Hi, I am facing an issue while translating "*" character. This is what I need Input=/path/to/the/file/data_file*.txt*.tar.gz Output=/path/to/the/file/data_file\*.txt\*.tar.gz When I try - echo $Input | tr '*' '\*' nothing happens. Is there a way to achieve the Output? -dips (4 Replies)
Discussion started by: dips_ag
4 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

8. Shell Programming and Scripting

Exactly How can we define "sh ksh csh &bash"

Hi - I m prashant. I m new in UNIX&LINUX world. I want to ask that how can we define the shell in Linux like bash,ksh,csh in Linux. What is the use of these shells. I know there are mny experts on net if you can tell me then please do me this favour and tell me about this topic. ... (1 Reply)
Discussion started by: prashantsingh
1 Replies

9. UNIX for Dummies Questions & Answers

Preventing wildcard expansion in "read"

Hi, I'm trying to use "read" to read in SQL lines and then apply to UDB. However KSH is expanding the *'s in the SQL into a list of all the files in the current directory... Anyway to turn this off? while read SQLStatement do echo "Running : " $SQLStatement... (8 Replies)
Discussion started by: gaijin 06
8 Replies
Login or Register to Ask a Question