Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My target is to verify if $FILE is a backup file ( backup file ended with xxxx.xx.xx.xx number

Example of backup files

ls /etc/VRTSvcs/conf/config

Example of not backup file

I write the following ksh script line in order to verify if $FILE ended with xxxx.xx.xx.xx number


     [[ ` echo  $FILE  | grep -v  '[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{2\}' `  -eq 0 ]] && echo Not Backup file

I set the


and I run this line on Solaris/Linux , but I get "Not Backup file" , in spite $FILE ended with 2012.09.10.31

please advice what the problem with my ksh line ( what need to fix ) in order to match the numbers - xxxx.xx.xx.xx

share|improve this question
up vote 3 down vote accepted

Just remove the "-eq 0 "

[[ ` echo  $FILE  | grep -v  '[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{2\}' ` ]] && echo Not Backup file
share|improve this answer

An inline command substitution returns the output of the command, not the return code

  ` echo  $FILE  | grep -v  '[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{2\}' ` 

would return an empty string, not a zero. Therefore this oneliner would not work as expected.

share|improve this answer

Why can't we use builtin Regexp with BASH/KSH for this? Where FILE1 is your backfile name

[[ "$FILE1" =~ [0-9]{4}\.[0-9]{2}\.[0-9]{2}\.1[0-9]{2} ]] || echo "Not a backup file"

Time/CPU utilization for this zero. Unnecessarily you are using three commands, echo two times and grep once.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.