I realize you have already solved your problem, but I will share a different solution that may be of use at some point:
Instead of wrapping the body of the for-loop within the file test, I test the inverse. If it is not a file, skip the rest of the loop's statements. This keeps the code from being needlessly idented (not a big deal here, but it can be with a more complex script).
The case statement is portable and can be easily extended to handle different actions for different patterns (or multiple patterns for the same case).
You probably want to use ${filename##*/} instead of ${filename#*/}. They both give the same result when there's only one slash in the pathname, but, when there are multiple, the former will return the basename of the file while the latter will only strip the first directory component.
Personally, I don't use echo when handling indeterminate data (like filenames, user input, etc), because problems can arise if the data looks like an option (and -- to disable option processing isn't supported).
This is very basic. Yet Iam struggling to get the right pattern for my check.
Apologize in advance to ask a very lame question.
I have to validate if a value of the variable starts with "efgh" and followed by 6 numbers.
Var1="efgh234567"
The condition Iam trying to achieve is similar to... (6 Replies)
This is on a CentOS box, I have two scripts that need to run in order.
I want to write a shell script that calls the first script, lets it run and then terminates it after a certain number of hours (that I specify of course), and then calls the second script (they can't run simultaneously) which... (3 Replies)
Hello ,
I have to search for the file names which will either has ABC_DEF or NN in their filename
Please note that both cannot appear in the same file name
currently I am using
ls -lrt /zthetl/SrcFiles/*ABC_DEF*.xls| head -1 | nawk '{print $9}'
How to combine the NN in this code?... (4 Replies)
I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Hi,
Here is my question: suppose I have files like
1990_8xdaily_atmos.nc
1991_8xdaily_atmos.nc
1992_8xdaily_atmos.nc
1993_8xdaily_atmos.nc
1990_daily_atmos.nc
1991_daily_atmos.nc
1992_daily_atmos.nc
1993_daily_atmos.nc
1990_month_atmos.nc
1991_month_atmos.nc
1992_month_atmos.nc... (1 Reply)
hi i want to know how to do this
if the given is /tmp/ and it is a valid directory then it will echo directory
if the given is /tmp/file.txt and is a valid file then it will echo file..
thanks! (5 Replies)
How do I check that a string $AA22CC3 starts with the "$" symbol ?
I have tried :
checksum='$AAB3E45'
echo $checksum
case $checksum in
$* ) echo success ;
esac
Thanks ... (4 Replies)
Hi all,
I have a question..
Here is my requirement..I have 500 files in a path say /a/b/c
I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
the script on excution should take a directory path from useran a numric input and it should check indicate whether its write or not?
if the cmmd sh<script-name>,dir/path.<500>" is greater than 500 in size should be copied to dir ,temp in pwd and display the mesage'files of 2000 bytes hav been... (4 Replies)