The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular Expressions ramky79 UNIX for Advanced & Expert Users 3 05-21-2008 05:13 PM
regular expressions whatever Shell Programming and Scripting 4 05-20-2007 04:30 PM
Help with regular expressions arushunter Shell Programming and Scripting 13 12-24-2006 12:31 AM
regular expressions in c++ szzz High Level Programming 2 10-06-2003 10:33 AM
Regular Expressions AresMedia Shell Programming and Scripting 1 08-22-2002 03:55 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-12-2006
jack1981 jack1981 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 42
regular expressions

Hi,

can anyone advise me how to shorten this:


if [ "$A" = "y" ] || [ "$A" = "Y" ] ; then

I tried [yY] but it dosent seem to work, whats the correct way.

Cheers
  #2 (permalink)  
Old 07-12-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
#!/bin/ksh
if [[ "$A" = [Yy] ]] ; then
   -- do stuff here
fi
  #3 (permalink)  
Old 07-12-2006
jack1981 jack1981 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 42
Thanks Jim!
  #4 (permalink)  
Old 07-12-2006
jack1981 jack1981 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 42
Hi,

Sorry to bother you again, can I shorthand this also?

if ! [ -f "$@" ] && ! [ -d "$@" ]; then

again I tried this:

#if ! [ -f -d "$@" ]; then

but it didn't work, I have some code which works to about 90% as I need it but I want to reduce the code as much as possible.

Thanks again!
  #5 (permalink)  
Old 07-12-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
no -

-f checks if the file exists and is a regular file
-d checks if the file exists and is a directory

These are mutually exclusive, so you have to make both tests, and they need to be separate tests maybe like this
Code:
if [[  ! -f "$@"  && ! -d "$@"   ]] ; then 
-- do stuff
fi
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0