Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
hey everyone.
I'm building my first BASH programs and I have a hard time.
I can't do a search in a folder and filter only script files without extension, the problem is to differentiate the script files from the others.
I tried with ls I tried with find and i don't find a way to make it work
Can somebody help me?
It's hard to help you without understanding exactly what you're trying to do and seeing the code.
From my basic understanding you are wanting to be able to perform a directory list and remove entries that are shell scripts (to be fair your scripts shouldn't be in your data directories-- they should be in /usr/local/appropriate-directory-for-function-or-item), but you can filter out things with a .sh on the end using an if statement or a find or even sed depending on the particulars of how you're calling things and specifically what you're doing. For example using -prune with find, or excluding files with the execute bit set, etc.
It's hard to help you without understanding exactly what you're trying to do and seeing the code.
From my basic understanding you are wanting to be able to perform a directory list and remove entries that are shell scripts (to be fair your scripts shouldn't be in your data directories-- they should be in /usr/local/appropriate-directory-for-function-or-item), but you can filter out things with a .sh on the end using an if statement or a find or even sed depending on the particulars of how you're calling things and specifically what you're doing. For example using -prune with find, or excluding files with the execute bit set, etc.
thanks for answer my call so quickly.
rweaver I'll try to explane more clearly.
I just want to list all files that are shell scripts.
I have a folder where I mixed many types of files
The files has no extension (.ch or .txt or .pdf)
There are files in that folder (Phiton and Bash script) that are the ones I want to list
catkin, was a good guess but the problem is that the script's return ASCII text as well as text, I still need to differentiate them, but I think you put me on the good track.
File will tell you what you want to know if the scripts are using the (fairly) standard:
#!/path/executable
First line, even if your version only returns ascii text that is valuable information (it's not a binary) and you can head -1 the file to pick up what scripting language its using... or alternate grep that file for specifics of the language that isn't going to be in other languages.
That's a very good solution as long as they at least followed the convention of adding the executable to the top of the file. If not it'll be considerably messier.
1. even though they're not reqd, do use file extensions where a convention exists eg .sh
2. do put the shell prog as the first line of the script eg
#!/usr/bin/bash
If you haven't done either of these, the you're going to jave to use the 'file' cmd to get 'text' files and check/rename them by hand. hopefully not too many to do.
If I had a lot, I'd write another script to do some basic parsing eg look for bash keywords. Could be tricky unless you know your scripts well.
Another search option is looking for the 'x' permission; should only be on runnable files.
first of all, I would like to thank everyone for their precious help
Tinkster, WOW Mastre solution, I'm still analyzing it.
ok, I'll explain mine solution first.
I created a test folder with ".sh" files and inside I created another folder with duplicates of my ".sh" files, (with and witout extentions), the problem is that in my later scripts (untested) I forgot to declare "#!/bin/bash" so the shell recognized "ascii". I'v rectifyed this detail and the "file *" (thanks catkin) workd wonder. after that i just filter with "fgrep" and magic happened.
here is the code you can use in /usr/bin/ fo test:
Code:
file /usr/bin/* | fgrep 'shell script'
now i whant the code to make the sherch in an file tree (it will bw an option in the script) anny suggestions
Last edited by Marcopredador; 02-12-2010 at 12:05 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.