ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm sorry if this is too basic.
I need to pin some files down in a directory to make a bash script with them.
I want to select the file containing '*-reduced.html' string in its name among these ones:
#!/bin/sh
START_LOCATION=/home
FILE_PATTERN='*-reduced.html'
# Search a directory tree
for i in `find $START_LOCATION -name $FILE_PATTERN `; do
echo $i
done
# Search a single directory
for i in `ls $START_LOCATION/$FILE_PATTERN`; do
echo $i
done
Thanks.
No, I'm not after a boolean; I need to do all sorts of things (basename, rename, zip, rm, etc.) to that precise file while keeping all the other files in the directory unchanged.
I need to be able to do for instance
zip $(basename $FILE_PATTERN .html).zip $FILE_PATTERN
in a loop and then move on to the next file manipulation loop like
FILE_ANOTHER_PATTERN='*-snapshot.html'
for FILE_ANOTHER_PATTERN in *
do
#!/bin/sh
START_LOCATION=/home
FILE_PATTERNS="*-reduced.html \
*-whatever.html \
*-linux.html"
# Search a directory tree
for PAT in $FILE_PATTERNS; do
echo "Processing pattern $PAT"
for i in `find $START_LOCATION -name $PAT `; do
echo Processing file $i
# gzip $i
done
done
P.S.
I changed #!/bin/sh to #!/bin/bash in the script and it worked as well.
Why so much irritation about bash? I don't know anything about other shells!
bash is the default shell in Linux, capabilities based on commercial ksh which is common on commercial Unices (sic).
It only appears to be irritating (here) because it's a programming lang, but newer people tend to hope that doing what seems simple to a human is so to a computer. It ain't so.
IOW, all langs take some time to learn....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.