[SHELL] Executable? Run it!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [SHELL] Executable? Run it!
# 1  
Old 10-06-2011
[SHELL] Executable? Run it!

I would like to make a script that I can see if the file is executable. If it is executable then it needs to run. Otherwise, if it is not executable the file needs to be edited, and run agian.

I hope you understand what i mean. Smilie

Thanks for the netherlands
# 2  
Old 10-06-2011
Code:
man test

Code:
if [ -x file ]; then
 echo file is executable
fi

# 3  
Old 10-06-2011
Code:
for files in `ls /your/directory/here`
do
if [ -f $files ]; then
sh $files
fi
done

this i think would execute anything that is a file within your directory.
or if you want to actually change permissions of the files first do the below

Code:
for files in `ls /your/directory/here`
do
if [ -f $files ]; then
chmod 755
sh $files
fi
done

# 4  
Old 10-06-2011
Code:
[ -x file ] || chmod +x file; ./file

# 5  
Old 10-06-2011
Quote:
Originally Posted by Tommyk
Code:
for files in `ls /your/directory/here`

That's an inefficient and error-prone way to iterate over the contents of a directory. Not only does it have to spawn a copy of the shell and an instance of ls, but it will choke on any pathnames containing IFS characters (by default, space, tab, and newline). A simple shell pathname expansion (aka file glob) is safe and efficient.

Code:
for files in /your/directory/here/*


Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Run executable in one directory and then move to another successively

Hello, I have several hundred subdirectories which contain input files for a binary executable. I need to get into each of the subdirectories, run the executable and then move to the next one and repeat the process. What is the best way to do this? Arbitrarily my file structures look like... (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

2. UNIX for Advanced & Expert Users

Figure out the minimum os version neede to run executable or link library.

Hello, I need to figure out the minimum OS version needed to run some executable. For the following OS: Linux, AIX, Solaris. For example how do I know the minimum OS version for /bin/ls ? "file" command does not give me much information. There are some tools that are helpful for understanding... (4 Replies)
Discussion started by: +Yan
4 Replies

3. UNIX for Dummies Questions & Answers

Can't run the archiver executable error message

I am using the xarchiver on a xfce environment. When compressing a directory using xarchiver which has both files and subdirectories, I encounter the following error: Can't run the archiver executable: Failed to execute child process "tar" (Argument list too long) Does anyone know exactly what... (0 Replies)
Discussion started by: figaro
0 Replies

4. Shell Programming and Scripting

Question on tweaking the PATH variable to allow the world to run my executable script

All, I am pretty new to Unix and still in the learning curve :) I have a simple requirement for which I did not get an answer yet (Atleast I do not know how to keyword the search for my requirement!!!). I have an executable script my.script1 in a folder /data/misc/scripts/dev, which when... (5 Replies)
Discussion started by: bharath.gct
5 Replies

5. Shell Programming and Scripting

Automatically select records from several files and then run a C executable file inside the script

Dear list its my first post and i would like to greet everyone What i would like to do is select records 7 and 11 from each files in a folder then run an executable inside the script for the selected parameters. The file format is something like this 7 100 200 7 100 250 7 100 300 ... (1 Reply)
Discussion started by: Gtolis
1 Replies

6. Shell Programming and Scripting

script run when executable is launched

I need to know how to have a BASH script run every time Firefox is launched, what is the simplest way to do this? (1 Reply)
Discussion started by: glev2005
1 Replies

7. Shell Programming and Scripting

Exit shell after setting executable to run?

Hi, I have an executable file that has a rather long and tedious process to complete. How would I launch the executable using the shell, and then exit the shell while leaving the executable to run in the background? (1 Reply)
Discussion started by: pcwiz
1 Replies

8. Shell Programming and Scripting

run and make an executable file

as i said before i'm a beginner in shell programming and i have two questions: how to run an executable file in shell scripts like for example let's say the file called "prog.exe", what's the shell command to run this file? also how can i make the shell file an executable file (if it is... (5 Replies)
Discussion started by: _-_shadow_-_
5 Replies

9. Shell Programming and Scripting

Need to call an Executable (.exe) using shell

Hi all , I need to call an executable (.exe) using shell script. Actual need is i need to call that shell script and do an export of some tables is there any way . the executable is datamover Please let me know if there are any option !! (2 Replies)
Discussion started by: raghav1982
2 Replies

10. UNIX for Dummies Questions & Answers

Cannot run UNIX executable !

I have installed the Darwin Calendar Server on my Mac and got it working. To start the server I open a Finder window on my mac and click the UNIX executable called RUN. In order to start the server automatically on bootup I used LINGON to add a startup Daemon to call "RUN -d". When I reboot... (6 Replies)
Discussion started by: thylacine
6 Replies
Login or Register to Ask a Question