LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   scripting problem,its annoying (https://www.linuxquestions.org/questions/linux-newbie-8/scripting-problem-its-annoying-52820/)

roo 04-01-2003 02:41 AM

scripting problem,its annoying
 
hi i need to know how to answer the following problem,i have a version but im getting errors i can't seem to fix,any help will be appreciated:
iam required to list all executeable files in a specified directory.the script works as follows
./exexcFiles[directory][file]

if no file is specified then result is displayed to the screen.if a file is specifired the results are sent to it.errror messages are to be included also.
my version so far is:
clear
currentDir = $PWD

if [$# -gt 0 -a $# -lt 2];
then
echo "you need to enter an argument"


elif [test -d $1];
then
cd $1
touch newFile
for i in *
do
if -x $i -a -f $i
echo -e "$i"
mv "$i"/"$newfile"
done

if [$# -eq 2];
then
echo "a file name has been entered"
touch $2
mv "newFile"/"$2"
mv "$2"/"$currentDir"
fi

bentz 04-01-2003 04:56 AM

Keep in mind that your 'if' statements must be terminated. For every 'if', there must be a 'fi'.

While I'm not totally positive what you are trying to do (looks like a lot of code just to find executables), it might make the most sense to use 'find -perm +4' or '+7'. Depending on the permissions you are looking for, find can search and return a list of files with specific permissions. Check out 'man find' for more info. For a more lightweight method, you could use 'ls -l | grep rwx' (or 'r-x').

roo 04-02-2003 03:47 AM

thanks for that.it was mostly syntax errors in the end.


All times are GMT -5. The time now is 02:20 PM.