Why doesn't this Bash shell compile directories?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why doesn't this Bash shell compile directories?
# 8  
Old 05-13-2013
I think this will achieve what you have asked for. However, I'm not sure that what you asked for is what you want.


Create the script (I'm using Bourne shell because there is nothing that needs the heavy duty of bash):

Code:
        cat > 223697.sh
#! /bin/sh
#       223697.sh - compile (contents of) directories


        dirs=`find . -mount -maxdepth 1 -mindepth 1 -type d`

        for dir in $dirs
        do
                cd $dir
                gcc *.c
                cd ..
        done

^D

NB the next step does NOT compile anything; it simply makes it executable.

Code:
chmod u+x 223697.sh

NB Do NOT type a dollar-sign ($) to run it. Just enter:

Code:
./223697.sh

This will compile all the C code in all the subdirectories. However,

Quote:
When you invoke GCC, it normally does preprocessing,
compilation, assembly and linking.

GCC(1)
I'm not sure if you really want 'gcc *.c', but that's what your code had.
This User Gave Thanks to hmg For This Post:
# 9  
Old 05-14-2013
Quote:
Originally Posted by hmg
I think this will achieve what you have asked for. However, I'm not sure that what you asked for is what you want.


Create the script (I'm using Bourne shell because there is nothing that needs the heavy duty of bash):

Code:
        cat > 223697.sh
#! /bin/sh
#       223697.sh - compile (contents of) directories
 
 
        dirs=`find . -mount -maxdepth 1 -mindepth 1 -type d`
 
        for dir in $dirs
        do
                cd $dir
                gcc *.c
                cd ..
        done

^D

NB the next step does NOT compile anything; it simply makes it executable.

Code:
chmod u+x 223697.sh

NB Do NOT type a dollar-sign ($) to run it. Just enter:

Code:
./223697.sh

This will compile all the C code in all the subdirectories. However,

I'm not sure if you really want 'gcc *.c', but that's what your code had.
Thanks very much for replying, that is exactly what I wanted. I managed to get the BASH one working awsell but can't post the code up just atm.

Cheers for the help guys Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Bash] passing variables to executable doesn't work

Bash version 4.4.20 / Ubuntu 16.0.4 Hello, I tried to write a script that gathers some data and passes them to an executable. The executed application answers with an error. The echo output in the script returns correct values. If I copy/paste the last echo command, it get's executed... (2 Replies)
Discussion started by: sushi2k7
2 Replies

2. UNIX for Beginners Questions & Answers

Bash diff date doesn't work

Hi everyone, I've an issue trying to soustracte two dates, e.g: d1=$(date -d "Nov 18, 2017" +%s) d2=$(date +%s) # Today we are 2017-11-16 echo "$(( (d1 - d2) / 86400 ))" Output: 1 I don't understand why it doesn't work. for me, it should give "18 - 16 = 2". Much appreciated... (1 Reply)
Discussion started by: Arnaudh78
1 Replies

3. Shell Programming and Scripting

Move directories in script.sh doesn't work

Dear All, I would like move some directories in another location. Basically, my ls -lis drwxr-xr-x 3 XXXXXXXXXXXXXXXXXXXX 4096 Feb 24 02:18 data.N701_N502.ABCDE -rw-r--r-- 1 XXXXXXXXXXXXXXXXXXXX 185865797 Feb 23 11:27 data.N701_N502.ABCDE_file1 -rw-r--r-- 1 XXXXXXXXXXXXXXXXXXXX... (2 Replies)
Discussion started by: giuliangiuseppe
2 Replies

4. OS X (Apple)

OS X 'find' nogroup/nouser doesn't traverse directories?

flamingo:~ joliver$ sudo find / -nogroup find: /dev/fd/4: No such file or directory find: /home: No such file or directory find: /Library: No such file or directory find: /net: No such file or directory find: /Network: No such file or directory find: /private: No such file or directory find:... (2 Replies)
Discussion started by: jnojr
2 Replies

5. Shell Programming and Scripting

pipe to grep doesn't work in bash script

Hi, I'm trying to write a script that checks gvfs to see if a mount exists so I can run it from network-manager's status hooks. I thought I'd pipe the output of gvfs-mount -l to grep for the particular mounts I care about. When I do this in a bash script: cmnd="gvfs-mount -l | grep -i... (4 Replies)
Discussion started by: kcstrom
4 Replies

6. Shell Programming and Scripting

bash script to compile multiple .c files with some options

I'm trying to write a bash script and call it "compile" such that running it allows me to compile multiple files with the options "-help," "-backup," and "-clean". I've got the code for the options written, i just can't figure out how to read the input string and then translate that into option... (5 Replies)
Discussion started by: travis.batzer
5 Replies

7. Ubuntu

set completion-ignore-case on doesn't work in bash

completion-ignore-case option doesn't work in my version: /home/user $ echo $BASH_VERSION 3.2.48(1)-release /home/user $ ls -l * -rw-r--r-- 1 user user 0 2009-10-18 00:09 somefile -rw-r--r-- 1 user user 0 2009-10-18 00:09 Somefile /home/user $ set completion-ignore-case on But when I... (2 Replies)
Discussion started by: Sapfeer
2 Replies

8. Shell Programming and Scripting

sftp mget where file doesn't exist BASH

I have a script that is working: #!/bin/bash sftp user@domain.com <<EOF cd somedir mget *.csv quit EOF but on a crontab I want to only pull newer files, so I want to do something like: while read ls current dir local file != true do mget that new file but I'm not sure the syntax... (2 Replies)
Discussion started by: unclecameron
2 Replies

9. Shell Programming and Scripting

Perl cmds doesn't work in Bash shell . Plz help

Hi everyone, I have a Linux OS in my PC (older version 9). Its default shell is bash. Whenever I try to run some Perl program it throws error ! eg, if I run this simple PERL program , #!/usr/bin/perl printf "\lHello \n"; $var=3 ; printf $var; @list=(1,2,3); printf "@list";... (6 Replies)
Discussion started by: adc22
6 Replies

10. UNIX for Dummies Questions & Answers

bash pattern matching echo *[! '/' ] doesn't work

without using ls, just using echo so purely pattern matching I can say echo */ <-- lists directories but how would I match files? surely something like *!/ or * but neither work ? it seems like there isn't much that I can put in but surely i should be able to put any ascii... (1 Reply)
Discussion started by: james hanley
1 Replies
Login or Register to Ask a Question