Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Given a shell script, is there an easy way to extract what files it manipulates explicitly (so not like concatenating some command and than eval-ing it)? E.g.

 #!/bin/bash

. /etc/someconfig.cfg

    cat /somedir/somefile.txt

    cp /otherdir/file1.txt /tmp/fileABC.txt

    rm -f ~/stupidfile.txt

    #EOF

Is there a command that would extract the explicit dependencies so that I don't have to parse the script or do it manually and get output like:

/etc/someconfig.cfg    
/somedir/somefile.txt
/otherdir/file1.txt 
/tmp/fileABC.txt
~/stupidfile.txt

?

Thanks

share|improve this question
1  
It's not possible in general to examine source code in a reasonably powerful programming language and deduce what external resources it will attempt to use if it is run. –  Celada Dec 26 '12 at 22:02
    
OK. i thought there could be a shell interpreter option to extract script metadata dependencies –  amphibient Dec 26 '12 at 22:04

1 Answer 1

Parsing the program is a reasonable approach to solve this (especially in an interpreted language).

If you have a static script without branches, you could do an strace -e open -f for the script to see which files it does open.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.